Codeforces Round #323 (Div. 2) D. Once Again... 乱搞+LIS
1 second
256 megabytes
standard input
standard output
You are given an array of positive integers a1, a2, ..., an × T of length n × T. We know that for any i > n it is true that ai = ai - n. Find the length of the longest non-decreasing sequence of the given array.
The first line contains two space-separated integers: n, T (1 ≤ n ≤ 100, 1 ≤ T ≤ 107). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 300).
Print a single number — the length of a sought sequence.
4 3
3 1 4 2
5
The array given in the sample looks like that: 3, 1, 4, 2, 3, 1, 4, 2, 3, 1, 4, 2. The elements in bold form the largest non-decreasing subsequence.
题意:给你一个序列n,有T个连续这样的序列,求最长不下降子序列的长度;
思路:发现T很大,n很小对吧,
显然中间肯定是有一段是连续的相同的数对吧;
开始想前面取一个LIS,最后取一个LIS,中间相同,数量最多的那个数;
这个做法错误,可能后面的前一个还能多取;
如果T<=n比较小,我们只需要暴力跑LIS即可;
现在讨论T>n的情况;
然后发现只有n个数,也就是说最后的LIS最多只有n段不同的数;
也就是说我们只需要拿出n段序列出来,跑LIS即可;
因为最多n段,然后取完n段,多余的可以从中间插入;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define mk make_pair
#define eps 1e-7
#define bug(x) cout<<"bug"<<x<<endl;
const int N=1e5+,M=1e6+,inf=;
const ll INF=1e18+,mod=; /// 数组大小
int arr[N],ans[N],len;
int binary_search(int i)
{
int left,right,mid;
left=,right=len;
while(left<right)
{
mid = left+(right-left)/;
if(ans[mid]>arr[i]) right=mid;
else left=mid+;
}
return left;
}
int LIS(int p)
{
ans[] = arr[];
len=;
for(int i=; i<=p; ++i)
{
if(arr[i]>=ans[len])
ans[++len]=arr[i];
else
{
int pos=binary_search(i);
ans[pos] = arr[i];
}
}
return len;
}
int flag[N];
int main()
{
int n,T,maxx=;
scanf("%d%d",&n,&T);
for(int i=;i<=n;i++)
scanf("%d",&arr[i]),flag[arr[i]]++,maxx=max(maxx,flag[arr[i]]);
for(int i=;i<n;i++)
for(int j=;j<=n;j++)
arr[i*n+j]=arr[j];
if(n>=T)printf("%d\n",LIS(n*T));
else printf("%d\n",LIS(n*n)+maxx*(T-n));
return ;
}
Codeforces Round #323 (Div. 2) D. Once Again... 乱搞+LIS的更多相关文章
- Codeforces Round #324 (Div. 2) Marina and Vasya 乱搞推理
原题链接:http://codeforces.com/contest/584/problem/C 题意: 定义$f(s1,s2)$为$s1,s2$不同的字母的个数.现在让你构造一个串$s3$,使得$f ...
- Codeforces Round #323 (Div. 1) B. Once Again... 暴力
B. Once Again... Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/582/probl ...
- 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 ...
- 重复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) 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 ...
- Codeforces Round #323 (Div. 2) D 582B Once Again...(快速幂)
A[i][j]表示在循环节下标i开头j结尾的最长不减子序列,这个序列的长度为p,另外一个长度为q的序列对应的矩阵为B[i][j], 将两序列合并,新的序列对应矩阵C[i][j] = max(A[i][ ...
随机推荐
- 使用gradle构建多模块springboot项目,打jar包
官方文档: https://spring.io/guides/gs/rest-service/ 参考:http://blog.csdn.net/u013360850/article/details/ ...
- [py][mx]django邮箱注册的验证码部分-django-simple-captcha库使用
邮箱注册-验证码 验证码使用第三方库django-simple-captcha 这个安装图形插件步骤官网有哦 - 1.Install django-simple-captcha via pip: pi ...
- [py]python内存管理
Python深入06 Python的内存管理 堆栈内存 - 堆内存 对象一般就是开辟在堆上的结构体: 堆内存用于提供 引用数据类型存储值 对象存储的是属性名和属性值 函数存储的是函数体代码字符串 函数 ...
- IP设置-内置服务器-外置服务器
HBulider 中 运行 -> 设置web服务器 -> 内置服务器将 127.0.0.1 换为局域网的ip,可以在局域网内所有电脑,手机上浏览页面.但是只能浏览html,php asp等 ...
- Qt 布局管理器
在一个颜值当道的今天,无论买衣服,买车还是追星,颜值的高低已经变成了大家最看重的(不管男性女性都一样,千万别和我说你不是):而对于程序猿来说,开发一款软件,不再只注重逻辑和稳定性,美观和用户友好性也是 ...
- linux文件系统软链接硬链接
引子 目前,UNIX的文件系统有很多种实现,例如UFS(基于BSD的UNIX文件系统).ext3.ext4.ZFS和Reiserfs等等. 不论哪一种文件系统,总是需要存储数据.硬盘的最小存储单位是扇 ...
- C#:文件、byte[]、Stream相互转换
一.byte[] 和 Stream /// <summary> /// byte[]转换成Stream /// </summary> /// <param name=&q ...
- FRM-40212: Invalid value for field %s.
Cause: Caused by one of the following: 1. The value is not of the proper data type. 字段类型不对 2 ...
- uva12083 二分图 求最大独立集 转化为求最大匹配 由题意推出二分图
这题大白书例题 : Frank 是一个思想有些保守的高中老师,有一次,他需要带一些学生出去旅行,但又怕其中一些学生在旅途中萌生爱意.为了降低这种事情的发生概率,他决定确保带出去的任意两个学生至少要满足 ...
- EditPlus 5.0 中文版已经发布(3月26日更新)
注意:新版本不再支持旧的注册码! 新特性: - Ctrl+Alt+Up/Down 键可添加多个插入点以及进行列选择 - Alt+鼠标点击可添加多个插入点 - 连续执行“选择单词”命令可将多个选中项添加 ...