http://codeforces.com/contest/583/problem/D

原题: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.

题目大意:有长度为n的数组a(n <= 100),其中a[i] <= 300,这个a数组可以重复T次,问他的最长上升子序列是多少?

思路:我们可以发现,这个数组如果要全部都算上的,那么在t<=n的情况下,他的最长上升子序列一定会遍历一次a数组。所以我们就只需要把原来的数组扩大n倍,然后求他的LIS。

这样以后我们发现,后面的重复的次数一定是原来数组里面出现次数(假定重复次数k为最多)最多的数值,所以ans = Lis的长度 + k * T - min(n, T);

复杂度 O(n*n*logn)

//看看会不会爆int!数组会不会少了一维!
//取物问题一定要小心先手胜利的条件
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker,"/STACK:102400000,102400000")
#define LL long long
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define haha printf("haha\n")
const int maxn = + ;
int a[maxn * maxn];
int n, T;
vector<int> ve; int solve(int t){
int len = t * n;
for (int i = ; i < t; i++){
for (int j = ; j <= n; j++){
a[n * i + j] = a[j];
}
}
for (int i = ; i <= n * t; i++){
int pos = upper_bound(ve.begin(), ve.end(), a[i]) - ve.begin();
if (pos == ve.size()) ve.push_back(a[i]);
else ve[pos] = a[i];
}
return ve.size();
} int cnt[maxn * maxn];
int main(){
cin >> n >> T;
int maxval = , k = ;
for (int i = ; i <= n; i++){
scanf("%d", a + i);
cnt[a[i]]++;
k = max(cnt[a[i]], k);
}
int ans = solve(min(n, T));
//printf("ans = %d k = %d T - min(n, T) = %d\n", ans, k, T - min(n, T));
printf("%d\n", ans + k * (T - min(n, T)));
return ;
}

重复T次的LIS的dp Codeforces Round #323 (Div. 2) D的更多相关文章

  1. DP Codeforces Round #303 (Div. 2) C. Woodcutters

    题目传送门 /* 题意:每棵树给出坐标和高度,可以往左右倒,也可以不倒 问最多能砍到多少棵树 DP:dp[i][0/1/2] 表示到了第i棵树时,它倒左或右或不动能倒多少棵树 分情况讨论,若符合就取最 ...

  2. DP Codeforces Round #260 (Div. 1) A. Boredom

    题目传送门 /* 题意:选择a[k]然后a[k]-1和a[k]+1的全部删除,得到点数a[k],问最大点数 DP:状态转移方程:dp[i] = max (dp[i-1], dp[i-2] + (ll) ...

  3. 数学+DP Codeforces Round #304 (Div. 2) D. Soldier and Number Game

    题目传送门 /* 题意:这题就是求b+1到a的因子个数和. 数学+DP:a[i]保存i的最小因子,dp[i] = dp[i/a[i]] +1;再来一个前缀和 */ /***************** ...

  4. 树形DP Codeforces Round #135 (Div. 2) D. Choosing Capital for Treeland

    题目传送门 /* 题意:求一个点为根节点,使得到其他所有点的距离最短,是有向边,反向的距离+1 树形DP:首先假设1为根节点,自下而上计算dp[1](根节点到其他点的距离),然后再从1开始,自上而下计 ...

  5. DP Codeforces Round #FF (Div. 1) A. DZY Loves Sequences

    题目传送门 /* DP:先用l,r数组记录前缀后缀上升长度,最大值会在三种情况中产生: 1. a[i-1] + 1 < a[i+1],可以改a[i],那么值为l[i-1] + r[i+1] + ...

  6. 递推DP Codeforces Round #260 (Div. 1) A. Boredom

    题目传送门 /* DP:从1到最大值,dp[i][1/0] 选或不选,递推更新最大值 */ #include <cstdio> #include <algorithm> #in ...

  7. Codeforces Round #323 (Div. 2) Once Again... CodeForces - 582B 最长非下降子序列【dp】(不明白)

    B. Once Again... time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  8. dp - Codeforces Round #313 (Div. 1) C. Gerald and Giant Chess

    Gerald and Giant Chess Problem's Link: http://codeforces.com/contest/559/problem/C Mean: 一个n*m的网格,让你 ...

  9. 拓扑序+dp Codeforces Round #374 (Div. 2) C

    http://codeforces.com/contest/721/problem/C 题目大意:给你有向路,每条路都有一个权值t,你从1走到n,最多花费不能超过T,问在T时间内最多能访问多少城市? ...

随机推荐

  1. 主题模型 利用gibbslda做数据集主题抽样

    电子科技大学电子商务实验室Kai Yip,欢迎同行指正,也欢迎互相指导,学习. 广告打完,进入正题. 关于程序运行结果的分析请参照我的另一篇博客:http://www.cnblogs.com/nlp- ...

  2. Visual Studio 2010 使用外部代码格式化工具 AStyle

    其中AStyle.exe 最好自己编译,放置到 Vistual Studio 安装目录\\Common7\\Tools 直接上配置截图: 单文件: 一次性格式化整个工程:

  3. ajax实现下拉列表联动

    下拉框代码 <fieldset style="margin-bottom:5px;"> <div class="form-group"> ...

  4. NDEF消息解析实例[转]

      问题:按照NDEF消息格式来解析下列Hex串? D1 02 1F 53 70 91 01 0E 54 02  65 6E 68 65 6C 6C 6F 20 77 6F  72 6C 64 51 ...

  5. SQL 小笔记

    如何得到字段的类型 select sql_variant_property(ID,'BaseType') from tb

  6. namenode无法启动

    查看日志错误信息关键语句: There appears to be a gap in the edit log.  We expected txid 44353, but got txid 原因: n ...

  7. 今天写动态canvas柱状图小结

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  8. wxpython 安装教程

    wxpython在windows 上的安装,需要在wxpython官网上下载对应的版本:Python分为32和64位系统不是系统的32位和64位 所以可以先在IDE 下输入Python看下当前是32还 ...

  9. ping 计算机全名,返回的不是IP地址

    今天想看一下机子的IP地址,结果关闭局域防火墙后,在命令行中使用ping 计算机全名,返回的不是IP地址 其实,这也是一种IP地址,IP6地址 原因:默认情况下,win7以上的操作系统,ping 计算 ...

  10. eclipse怎么连接到MySQL中的表!!!!!

    简介: 用eclipse编写的好的代码,我们怎么才能连接到数据库呢?对于初学者,特别是在连接数据库这块经常会发生一些莫名的错误,一般来说,归根是我们连接数据库这一过程发生错误.那么我们如何来解决呢?那 ...