codeforces round#323(div2 D)(思路)
2015-10-04 11:40
316 查看
题意:
给定一个长度不超过100的序列,让这个序列重复T(T<=1e7)次,求最长非递减序列的长度。
分析:
首先: 对于T<=200; 直接递推计算即可。
那么对于T>200的,我们先看一下这组成结果的T个分段,记有数字增长的为跳转段,没有的叫保持段。
首先,保持段都是最大的数字重复值,因为如果不是这样,那么把所有的段都替换成这样的段,结果会更好(跳转段所带来的最大优势不超过n , 可以想一下)
那么,这样就很明显了,直接取200以上的段 为保持段就好了。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
typedef long long ll;
using namespace std;
#define rep1(i ,x ,n) for(int i=x;i<=n;i++)
#define lowbit(x) (x&(-x))
const int N = 350;
int a
, cnt
,d
={0},n,T;
int main()
{
cin>>n>>T;
rep1(i ,1 , n) scanf("%d",&a[i]),cnt[a[i]]++;
int max_ = 0;
rep1(i ,1 , n) max_ = max(max_,cnt[a[i]]);
int min_ = min( T, 200);
rep1(i , 1 , min_) {
rep1(j , 1 , n){
int te = 0;
rep1(k ,1 ,n) if(a[k] <= a[j]){
te = max(te , d[k]+1);
}
d[j] = te;
}
}
int res = 0;
rep1(i ,1 , n) res = max(res , d[i]);
cout<<res + (T - min_) * max_ <<endl;
return 0;
}
给定一个长度不超过100的序列,让这个序列重复T(T<=1e7)次,求最长非递减序列的长度。
分析:
首先: 对于T<=200; 直接递推计算即可。
那么对于T>200的,我们先看一下这组成结果的T个分段,记有数字增长的为跳转段,没有的叫保持段。
首先,保持段都是最大的数字重复值,因为如果不是这样,那么把所有的段都替换成这样的段,结果会更好(跳转段所带来的最大优势不超过n , 可以想一下)
那么,这样就很明显了,直接取200以上的段 为保持段就好了。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
typedef long long ll;
using namespace std;
#define rep1(i ,x ,n) for(int i=x;i<=n;i++)
#define lowbit(x) (x&(-x))
const int N = 350;
int a
, cnt
,d
={0},n,T;
int main()
{
cin>>n>>T;
rep1(i ,1 , n) scanf("%d",&a[i]),cnt[a[i]]++;
int max_ = 0;
rep1(i ,1 , n) max_ = max(max_,cnt[a[i]]);
int min_ = min( T, 200);
rep1(i , 1 , min_) {
rep1(j , 1 , n){
int te = 0;
rep1(k ,1 ,n) if(a[k] <= a[j]){
te = max(te , d[k]+1);
}
d[j] = te;
}
}
int res = 0;
rep1(i ,1 , n) res = max(res , d[i]);
cout<<res + (T - min_) * max_ <<endl;
return 0;
}
相关文章推荐
- 关于*大学计算机科学与技术学院的大一学生几个关于Linux学习方面的疑惑之回复
- 解决PHP move_uploaded_file函数移动图片失败
- Substring with Concatenation of All Words字符串中找到包含所有单词的子串
- Set集合实现元素不重复原理
- DirectX11 裁剪像素
- 杭电OJ -- 2034 人见人爱A-B(c++练手的好题目)
- android studio安装中遇到的问题(ubuntu)
- symfony报错:Declaration of testAction::execute() must be compatible with sfComponent::execute($request
- 110. Balanced Binary Tree (Tree; DFS)
- 成员变量、类变量、局部变量的区别
- ios9 [app setStatusBarHidden:NO] is deprecated
- 两个栈实现队列
- 信息安全系统设计基础第三周学习总结
- 信息的表示和处理
- hdu 4513 吉哥系列故事——完美队形II(manacher)
- UVA 571 Jugs ADD18 小白书10 数学Part1 专题
- 104. Maximum Depth of Binary Tree (Tree; DFS)
- 程序设计基石与实践系列之C语言程序员必读的5本书
- 模数和数模转换电路
- 解决adb端口被占问题的几种方法总结