Codeforces Round #323 (Div. 1)-B. Once Again...
来源:互联网 发布:linux 小数比较大小 编辑:程序博客网 时间:2024/05/01 07:37
原题链接
B. Once Again...
time limit per test
1 secondmemory limit per test
256 megabytesinput
standard inputoutput
standard outputYou 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 33 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次,求出它的LIS然后再找出原序列中出现的次数最多的数插入在相应的位置。
#include <bits/stdc++.h>#define maxn 200005using 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 0
- Codeforces Round #323 (Div. 1) B. Once Again...
- Codeforces Round #323 (Div. 1)-B. Once Again...
- Codeforces Round #323 (Div. 2) D.Once Again...(582B)
- Codeforces Round #323 (Div. 1) B. Once Again... (最长不下降序列_DP)
- Codeforces Round #323 (Div. 1) B. Once Again... 最长非严格递增子序列
- Codeforces Round #323 D Once Again...
- Codeforces 582B Once Again...
- codeforces 583B B. Once Again...(dp)
- codeforces 583B B. Once Again...(LIS)
- [codeforces 582b]Once Again…
- Codeforces 582 B Once Again... (LIS)
- Codeforces 582B Once Again... 【LIS变形】
- Codeforces 582B Once Again... LIS变形
- 【Codeforces Round 323 (Div 2)D】【暴力 脑洞 插入贡献思想】Once Again... 循环节重复T次后的LIS
- codeforces Round 323D Once again(周期数列的最长非递减子序列)
- [DP]Codeforces Round #323 (Div. 2)DOnce Again...
- Codeforces Round #323 (Div. 2) B 模拟
- Codeforces Round #131 (Div. 1) B. Numbers
- java存储数据
- 修改pptp vpn的默认端口
- 判断xml,json,数组
- 又学一招——删除windows服务
- 30. Substring with Concatenation of All Words 找出包含所有字典中词的开头
- Codeforces Round #323 (Div. 1)-B. Once Again...
- gradle 构建错误:Unsupported major.minor version 52.0 解决办法
- MYSQL单表中各记录总和统计 适用于报表
- iOS中延时执行的几种方式
- OpenCV从入门到放弃(三):Core组件细讲
- Firebreath新建工程的过程及使用
- jquery validate addMethod 自定义验证方法
- 短信验证码---重新发送倒计时
- error C2065: 'IDD_MONDATAREPLYDLG' : undeclared identifier解决方法