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][ ...
随机推荐
- switch语句语法
switch case语句适用于从一组互斥的分支中选择一个执行分支. int day = 0;switch (day) { : dayName = "Sunday"; break ...
- python -- 解决If using all scalar values, you must pass an index问题
[问题描述] 在将dict转为DataFrame时会报错:If using all scalar values, you must pass an index 例如: summary = pd.Dat ...
- javascript unicode与GBK2312(中文)编码转换示例
一个javascript的unicode与GBK2312编码相互转换的方法. 代码: var GB2312UnicodeConverter = { ToUnicode: function (s ...
- .NET RSA解密、签名、验签
using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Sec ...
- window.open和window.showModalDialog
window.open window.open是打开一个新窗口 在window.open打开的窗口中刷新父页面 opener.location.reload(); 打开一个窗口格式:属性可以任意设置 ...
- Twitter OA prepare: Rational Sum
In mathematics, a rational number is any number that can be expressed in the form of a fraction p/q ...
- Math.abs(~2018) —— 入群问答题
这道题的关键点在于对位操作符“~”的理解,以及内部的具体实现(设计到补码) 最后的结果是:2019 参考文章: http://www.w3school.com.cn/js/pro_js_operato ...
- Linux命令: 编辑模式移动光标
敲命令按以下顺序 ①vim filename ②e ③i ④ESC 移动光标 0 (零):将光标移动到行的起始处. $:将光标移动到行的末尾处. H:将光标移到当前窗口(而非全文)的第一行起始处. M ...
- java接口对接——别人调用我们接口获取数据
java接口对接——别人调用我们接口获取数据,我们需要在我们系统中开发几个接口,给对方接口规范文档,包括访问我们的接口地址,以及入参名称和格式,还有我们的返回的状态的情况, 接口代码: package ...
- Linux基础命令---zip
zip zip是一种最通用的文件压缩方式,使用于unix.msdos.windows.OS等系统.如果在编译zip时包含bzip 2库,zip现在也支持bzip 2压缩.当将大于4GB的文件添加到存档 ...