E. Cubes codeforce 180/E
来源:互联网 发布:房产拍卖淘宝司法拍卖 编辑:程序博客网 时间:2024/04/30 11:02
Let's imagine that you're playing the following simple computer game. The screen displays n lined-up cubes. Each cube is painted one of m colors. You are allowed to delete not more than k cubes (that do not necessarily go one after another). After that, the remaining cubes join together (so that the gaps are closed) and the system counts the score. The number of points you score equals to the length of the maximum sequence of cubes of the same color that follow consecutively. Write a program that determines the maximum possible number of points you can score.
Remember, you may delete no more than k any cubes. It is allowed not to delete cubes at all.
The first line contains three integers n, m and k (1 ≤ n ≤ 2·105, 1 ≤ m ≤ 105, 0 ≤ k < n). The second line contains n integers from 1to m — the numbers of cube colors. The numbers of colors are separated by single spaces.
Print the maximum possible number of points you can score.
10 3 21 2 1 1 3 2 1 1 2 2
4
10 2 21 2 1 2 1 1 2 1 1 2
5
3 1 21 1 1
3
看到这道题想法不是很多,肯定不能一种一种判断k个容错的最长同种序列,而且还是如此长的一个序列。如何进行判断呢?既然是动态规划的题目,状态转移,这个状态转移与种类无关,可能要还某种特殊的表示方法?
每种的数量这种信息肯定没什么作用,k个和k-1个差别也可能是天壤之别,状态转移应该是根据m的吧,但是m的数量级否定了这个可能性。而k应该是作为一个一开始就知道的值代入的。
旁边有一些暗示,二分法,两个指针。不太想往这个暗示的方面去想,不过可以一试。
看了别人博客中的解法,用了Vector这个数据结构,基本上做的都用了这个数据结构。
没看出来哪里动态规划了其实,不过惊奇的是,它居然是从第一个元素到最后一个元素,一个个进行二分查找找到k距离可以容纳的个数,nlgn的复杂度原来也可以通过啊。长知识了。
下面附上网上找到的代码,过两天在自己试着写写:
#include<stdio.h>
#include<vector>
using
#define N 200009
int
int
{
}
别忘了相同元素间的除了不同元素还有相同元素,所以数组的序号相减后要减去向量的序号之差才是真正的这两个相同元素之间要删除的元素。
- E. Cubes codeforce 180/E
- Codeforces Round #116 E-Cubes 180E
- CodeForces Round #116 (180E) - Cubes
- 180E - Cubes DP 优先队列
- COdeforce 14E
- codeforce 18E
- (121E)codeforce
- Codeforce 445E
- CodeForce 27E
- codeforce 78E
- codeforce round 399# E
- Codeforce 785E(分块)
- codeforce 761E
- codeforce 416 E floyd
- codeforce 888E
- codeforce 899E
- CodeForces 180E Cubes--后续指针--当前个数
- CodeForces 180E Cubes(vector+尺取)
- UVA 1069
- 开发商发行游戏前应注意的五大问题
- Android 之 内存管理
- 使用SSH+VNC实现安全的Linux远程桌面管理
- C#如何判断一个字符串是16进制字符串
- E. Cubes codeforce 180/E
- POJ 3368 Frequent values
- Quartz Core 图层编程
- ArcGIS教程:河网分级
- Hadoop2.2.0伪分布式环境搭建(附:64位下编译Hadoop-2.2.0过程)
- 软件测试技术类面试题集锦
- URI和URL的区别
- 郑州市治疗精神抑郁症
- sublime text 编译lua(详细可靠)