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][ ...
随机推荐
- [LeetCode] 193. Valid Phone Numbers_Easy tag: Bash
Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...
- oracle怎么恢复被覆盖的存储过程
在oracle数据库中,如果覆盖了之前的存储过程,那得赶紧闪回,时长越长闪回的可能性越小. 原理很简单,存储过程的定义就是数据字典,修改数据字典跟修改普通表的数据没有区别,此时会把修改前的内容放到un ...
- Locust性能测试2-先登录场景案例
前言 有很多网站不登录的话,是无法访问到里面的页面的,这就需要先登录了 实现场景:先登录(只登录一次),然后访问页面->我的地盘页->产品页->项目页 官方案例 下面是一个简单的lo ...
- web前端面试小结(1)
两天大概面试了4家,有电面也有F2F,现将面试中的问题大概汇总下,一方面了解自己的不足,一方面用来勉励自己后面面试加油! 答案网上都有,就不一一写在这里了,后面有时间会把下面的问题分别拉出来详述. 1 ...
- kendo grid应用经验总结
学习网址 https://docs.telerik.com/kendo-ui/controls/editors/dropdownlist/overview https://demos.telerik. ...
- 3:4 OGNL 表达式二
总结: 一:ActionContext的结构: 1:set标签创建的对象也是作为非值栈对象. 2:(非值栈的存储都是以键值对的方式存的.) [问非值栈的 User对象] [用例] 关于request: ...
- python 同时迭代多个序列
每次分别从一个序列中取一个元素 >>> xpts = [1, 5, 4, 2, 10, 7] >>> ypts = [101, 78, 37, 15, 62, 99 ...
- 发布QT exe
https://blog.csdn.net/u014453443/article/details/85837138
- 微信小程序的功能开发工具跟公众号的差别,小程序是一种减负思维对简单APP是巨大打击
微信小程序的功能开发工具跟公众号的差别,小程序是一种减负思维对简单APP是巨大打击 摘要: 小程序和公众号最大的区别有如下四点:1.小程序没有粉丝,开发者在后台能看到的只能是累计用户访问数以及实时统计 ...
- silverlight数据绑定
控件绑定 <Grid x:Name="LayoutRoot"> <StackPanel> <ScrollBar x:Name="bar&qu ...