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 ...
随机推荐
- 使用SecureCRT上传和下载文件
SecureCR 下的文件传输协议有ASCII .Xmodem .Ymodem .Zmodem.ASCII:这是最快的传输协议,但只能传送文本文件.Xmodem:这种传输协议速度较慢,但由于使用了CR ...
- linux中fork()函数详解(转)
转自:http://blog.csdn.net/jason314/article/details/5640969 一.fork入门知识 一个进程,包括代码.数据和分配给进程的资源.fork()函数通过 ...
- 使用hibernate tools插件生成POJO
很多时候我们已经设计好了数据库,需要使用hibernate来做数据持久化,因此需要根据数据库中的表结构生成相应的POJO. 本例使用hibernatetools来自动创建pojo. 测试环境:ecli ...
- 自己定制Linux发行版(资料)
/******************************************************************** * 自己定制Linux发行版(资料) * 声明: * 随着L ...
- Spring入门之HelloSpring
Spring描述: -轻量级:Spring是非侵入式的-基于Spring开发的应用中的对象可以不依赖于Spring的API -依赖注入(DI---dependency injection,IOC) - ...
- [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.5.8
Prove that for any matrices $A,B$ we have $$\bex |\per (AB)|^2\leq \per (AA^*)\cdot \per (B^*B). \ee ...
- Myeclipse *.link用法
引用路径 path=D:\\ProgramData\\MyEclipse\\adt
- 4种activity的启动模式
在android里,有4种activity的启动模式,分别为: “standard” (默认) “singleTop” “singleTask” “singleInstance” 它们主要有如下不同: ...
- HDU 1078 FatMouse and Cheese 记忆化搜索DP
直接爆搜肯定超时,除非你加了某种凡人不能想出来的剪枝...555 因为老鼠的路径上的点满足是递增的,所以满足一定的拓补关系,可以利用动态规划求解 但是复杂的拓补关系无法简单的用循环实现,所以直接采取记 ...
- eclipse 远程wifi调试android程序
[原文]http://leanote.com/blog/view/541f8b2dbda4e44f75000000 下载wifidebug http://pan.baidu.com/s/1i3stnF ...