Codeforces Round #323 (Div. 1)-B. Once Again...

原题链接

B. Once Again...
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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.

Input

The first line contains two space-separated integers: nT (1 ≤ n ≤ 1001 ≤ 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, 23, 1, 4, 2, 3, 1, 4, 2. The elements in bold form the largest non-decreasing subsequence.


发现肯定有一段是连续的相同的,因此我们先将序列复制n次,求出它的LIS然后再找出原序列中出现的次数最多的数插入在相应的位置。

#include <bits/stdc++.h>
#define maxn 200005
using namespace std;

int num[105], vis[305];
int d[10005];
int main(){
	
	int n, t, maxs = 0;;
	
	scanf("%d%d", &n, &t);
	for(int i = 0; i < n; i++){
		scanf("%d", num+i);
		vis[num[i]]++;
		maxs = max(maxs, vis[num[i]]);
	} 
	int cnt = 0;
	for(int i = 0; i < min(n, t); i++)
	 for(int j = 0; j < n; j++){
	 	if(cnt == 0 || num[j] >= d[cnt-1])
	 	 d[cnt++] = num[j];
	 	else{
	 		int h = upper_bound(d, d+cnt, num[j]) - d;
	 		d[h] = num[j];
	 	}
	 }
	 if(t > n)
	  cnt += (t - n) * maxs;
	cout << cnt << endl;
	
	return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值