Codeforces Round #323 (Div. 1) B. Once Again... 暴力
B. Once Again...
Time Limit: 1 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/582/problem/B
Description
Input
Output
- Print a single number — the length of a sought sequence.
Sample Input
- 4 3
3 1 4 2
Sample Output
- 5
HINT
题意
给你一个n*t这么长的序列,然后求最长不递减序列
其中a[i+n]=a[i]
题解:
暴力,如果t<=300,我们就直接暴力求就好了
如果t>的话,我们就大胆猜测,中间肯定是连续选一个数
那么我们就预处理前面以a[i]开始的最长,和后面的以a[i]最长是啥就好了~
代码:
- #include<iostream>
- #include<stdio.h>
- #include<queue>
- #include<map>
- #include<algorithm>
- #include<string.h>
- using namespace std;
- #define maxn 3225020
- int a[maxn];
- int dp1[maxn];
- int dp2[maxn];
- int dp3[maxn];
- int lis[maxn];
- int main()
- {
- int n,t;scanf("%d%d",&n,&t);
- for(int i=;i<=n;i++)
- scanf("%d",&a[i]);
- if(t<=)
- {
- int ans = ;
- for(int i=;i<=n;i++)
- for(int j=;j<t;j++)
- a[j*n+i] = a[i];
- for(int i=;i<=n*t;i++)
- {
- lis[i]=;
- for(int j=;j<i;j++)
- if(a[i]>=a[j])
- lis[i]=max(lis[i],lis[j]+);
- ans = max(lis[i],ans);
- }
- printf("%d\n",ans);
- return ;
- }
- int k = ;
- for(int i=;i<=n;i++)
- dp2[a[i]]++;
- for(int i=;i<=n;i++)
- for(int j=;j<=k;j++)
- a[j*n+i] = a[i];
- for(int i=;i<=k*n;i++)
- {
- lis[i]=;
- for(int j=;j<i;j++)
- if(a[i]>=a[j])
- lis[i]=max(lis[i],lis[j]+);
- dp1[a[i]] = max(dp1[a[i]],lis[i]);
- }
- memset(lis,,sizeof(lis));
- reverse(a+,a++k*n);
- for(int i=;i<=k*n;i++)
- {
- lis[i]=;
- for(int j=;j<i;j++)
- if(a[i]<=a[j])
- lis[i]=max(lis[i],lis[j]+);
- dp3[a[i]] = max(dp3[a[i]],lis[i]);
- }
- int ans = ;
- for(int i=;i<=;i++)
- for(int j=i;j<=;j++)
- for(int m=j;m<=;m++)
- ans = max(dp1[i]+dp2[j]*(t-*k)+dp3[m],ans);
- printf("%d\n",ans);
- }
Codeforces Round #323 (Div. 1) B. Once Again... 暴力的更多相关文章
- Codeforces Round #323 (Div. 2) C. GCD Table 暴力
C. GCD Table Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/583/problem/C ...
- Codeforces Round #323 (Div. 2) B 贪心,暴力
B. Robot's Task time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #323 (Div. 2) D. Once Again... 暴力+最长非递减子序列
D. Once Again... You a ...
- 重复T次的LIS的dp Codeforces Round #323 (Div. 2) D
http://codeforces.com/contest/583/problem/D 原题:You are given an array of positive integers a1, a2, . ...
- Codeforces Round #323 (Div. 2) D. Once Again... 乱搞+LIS
D. Once Again... time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #323 (Div. 2) C. GCD Table map
题目链接:http://codeforces.com/contest/583/problem/C C. GCD Table time limit per test 2 seconds memory l ...
- Codeforces Round #323 (Div. 2) C.GCD Table
C. GCD Table The GCD table G of size n × n for an array of positive integers a of length n is define ...
- Codeforces Round #323 (Div. 1) A. GCD Table
A. GCD Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces Round #323 (Div. 2) E - Superior Periodic Subarrays
E - Superior Periodic Subarrays 好难的一题啊... 这个博客讲的很好,搬运一下. https://blog.csdn.net/thy_asdf/article/deta ...
随机推荐
- freemarker截取字符串
[#if a.title?length lt 23 ] ${a.title} [#else]${a.title[0..22]}...[/#if]
- 错误代码: 1005 Can't create table 'hibernate.bill' (errno: 150)
主要问题以及解决办法是: 1,MySQL支持外键约束,并提供与其它DB相同的功能,但表(外键表和外键主表)类型必须为 InnoDB,外键表和外键主表的类型都要是innoDB 建表约束语句: user表 ...
- bzoj1385: [Baltic2000]Division expression
欧几里得算法.可以发现规律,a[2]作为分母,其他作为分子,必定是最好的选择.判断是否为整数即可. #include<cstdio> #include<cstring> #in ...
- acdream 小晴天老师系列——晴天的后花园 (暴力+剪枝)
小晴天老师系列——晴天的后花园 Time Limit: 10000/5000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) ...
- android数据库(随apk一起发布数据库)
读取数据库+数据库版本更新 注意: a, 将随apk发布的数据库放在android工程下/res/raw路径下. b, 数据库文件存到手机上时,路径在/data/data/你的包名/databases ...
- SSH proxy
# for Linux ssh nobody@guoliangwu.com -P 22 -C -N -D 127.0.0.1:6500 # for windows(PuTTY) plink nobod ...
- 计算N的阶层
int factorial(int n) { int i, result; ; i <= n; i++) result *= i; return result; } int factorial2 ...
- NOIP2009 靶形数独
4.靶形数独 (sudoku.pas/c/cpp) [问题描述] 小城和小华都是热爱数学的好学生, 近,他们不约而同地迷上了数独游戏,好胜的他们想用数独来一比高低.但普通的数独对他们来说都过于简单了, ...
- 4.1Reduction模型
1. Reduction Reduction是一种广泛使用的计算模型,特别是在并行计算领域.简单地来说,Reduction就是一系列的划分(Partition)和汇总(Summarize)操作的集合: ...
- 【poj2891】Strange Way to Express Integers
题意: 给出n个模方程x=a(mod r) 求x的最小解 题解: 这就是个线性模方程组的模版题- - 但是有一些要注意的地方 extgcd算出来的解x可能负数 要让x=(x%mo+mo)%mo 而且 ...