链接:戳这里
D. Once Again...
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
Input
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).
Output
Print a single number — the length of a sought sequence.
Examples
input
4 3
3 1 4 2
output
5
Note
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倍,问最长上升子序列
思路:
给出的长度为n的子序列求LIS肯定很好算,那么我们分析一下,什么情况下会答案很大呢
如果给你的n个数是唯一的,(n=100)那么我算最长的也就是n*n了,为什么?
你能拿到的最长的数也就到第n*n,因为假设你每个n块里面取一个出来(至少有一个满足答案)
也就是n*n个,所以我们求到n*n也才10000,那么多出来的(T-n)怎么办
直接拿出现次数最多的那个数就行了
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include <ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<iomanip>
#include<cmath>
#define mst(ss,b) memset((ss),(b),sizeof(ss))
#define maxn 0x3f3f3f3f
#define MAX 1000100
///#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef unsigned long long ull;
#define INF (1ll<<60)-1
using namespace std;
int s[1000100];
int LIS(int *a,int n){
int len=0;
s[++len]=a[1];
for(int i=2;i<=n;i++){
if(a[i]>=s[len]) s[++len]=a[i];
else {
int x=upper_bound(s+1,s+len+1,a[i])-s;
/// s中>a[i]的第一个元素。
s[x]=a[i];
}
}
return len;
}
int n,T;
int a[1000100],b[1000100],vis[1000100];
int main(){
scanf("%d%d",&n,&T);
int num=0;
for(int i=1;i<=n;i++) {
scanf("%d",&a[i]);
vis[a[i]]++;
num=max(vis[a[i]],num);
}
int cnt=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
b[++cnt]=a[j];
}
}
ll ans=0;
if(T<=n){
ans=LIS(b,n*T);
} else {
ans=LIS(b,n*n)+(ll)num*(T-n);
}
cout<<ans<<endl;
return 0;
}