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. 利用java实现抽奖转盘(着重安全控制)

    本文是针对jquery 实现抽奖转盘作者的一个补充(主要用java去实现转盘结果生成及存储,解决jquery 做法 非法用户采用模拟器实现改变转盘值的风险性),针对jQuery的具体实现,请看案例:h ...

  2. 【NOIP2013提高组】货车运输

    货车运输  (truck.cpp/c/pas) [问题描述]  A国有n座城市,编号从1到n,城市之间有m条双向道路.每一条道路对车辆都有重量限制,简称限重.现在有q辆货车在运输货物,司机们想知道每辆 ...

  3. java 调用打印机 打印服务

    import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import javax ...

  4. laravel sum 多个字段

    laravel中怎么实现下面的SQL select sum('profit'),sum('order_count') from pro where......; 参考 self::where('id' ...

  5. uiwebview 加载html时字体变小 加载前或加载后改变字体大小

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #6122ae } p.p2 { margin: 0.0px 0. ...

  6. JavaScript DOM编程艺术-学习笔记(第三章、第四章)

    第三章: 1.js的对象分为三种:①用户自定义对象 ② 内建对象(js提供的对象) ③宿主对象(js寄宿的环境-浏览器,提供的对象) 2.文档是由节点组成的集合,即dom树,html元素是根元素,是唯 ...

  7. hdu5514 非2的次幂容斥原理

    /* 1 126 223092870 210 330 390 462 510 546 570 690 714 770 798 858 910 966 1122 1155 1190 1254 1326 ...

  8. MySQL导出csv乱码问题的解决

    csv乱码问题的解决      从MySQL导出数据到 csv 文件后,有时会发现用 excel 打开该导出 csv 文件显示的是乱码.这个问题是 csv 文件本身的文本编码问题导致的,解决办法: 1 ...

  9. [笔记]The Linux command line

    Notes on The Linux Command Line (by W. E. Shotts Jr.) edited by Gopher 感觉博客园是不是搞了什么CSS在里头--在博客园显示效果挺 ...

  10. javascript keycode

    keycode    8 = BackSpace BackSpacekeycode    9 = Tab Tabkeycode   12 = Clearkeycode   13 = Enterkeyc ...