挺有意思的一道题目。
考虑长度为n的数组,重复n次,可以得到n*n的最长上升子序列。同理,也可以得到n*n的最长下降子序列。
因此,把t分成prefix(上升子序列) + cycle(one integer repeating) + sufix(下降子序列)。
当t<=2*n时,暴力解。
注意数据范围。

 /* 583D */
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define sti set<int>
#define stpii set<pair<int, int> >
#define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define clr clear
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 const int maxn = ;
const int maxm = ;
int c[maxm];
int a[maxn], b[maxn*maxn*];
int dp[maxm];
int suf[maxn*maxn], pre[maxn*maxn]; int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif int n, t;
int mx;
int ans = ; scanf("%d %d", &n, &t);
rep(i, , n+) {
scanf("%d", &a[i]);
++c[a[i]];
} if (t <= n*) {
rep(i, , n+) {
int k = i;
rep(j, , t+) {
b[k] = a[i];
k += n;
}
} int n_ = n*t; memset(dp, , sizeof(dp));
rep(i, , n_+) {
mx = ;
rep(j, , b[i]+)
mx = max(mx, dp[j]);
pre[i] = ++mx;
dp[b[i]] = mx;
}
rep(i, , n_+)
ans = max(ans, pre[i]);
printf("%d\n", ans);
return ;
} rep(i, , n+) {
int k = i;
rep(j, , n+) {
b[k] = a[i];
k += n;
}
} // calculate prefix
int n_ = n*n; memset(dp, , sizeof(dp));
rep(i, , n_+) {
mx = ;
rep(j, , b[i]+)
mx = max(mx, dp[j]);
pre[i] = ++mx;
dp[b[i]] = mx;
} // calculate suffix
memset(dp, , sizeof(dp));
per(i, , n_+) {
mx = ;
rep(j, b[i], maxm)
mx = max(mx, dp[j]);
suf[i] = ++mx;
dp[b[i]] = mx;
} // iteration
int tmp, n2 = n+n; rep(i, , n+) {
rep(j, , n+) {
if (a[j] < a[i])
continue;
tmp = pre[i+n_-n] + suf[j] + c[a[i]]*(t-n2);
ans = max(ans, tmp);
}
} printf("%d\n", ans); #ifndef ONLINE_JUDGE
printf("time = %d.\n", (int)clock());
#endif return ;
}

【CF】323 Div2. D. Once Again...的更多相关文章

  1. 【CF】135 Div2 Choosing Capital for Treeland

    树形结构,挺有意思的题目.不难. /* 219D */ #include <iostream> #include <string> #include <map> # ...

  2. 【转载】#323 - A Generic Class is a Template for a Class

    A generic classs is a class that takes one or more type parameters, which it then uses in the defini ...

  3. 【Codeforces】383.DIV2

    昨天一场CF发挥不好.抽点时间总结一下,然后顺带算是做个题解. 第一题水题 第二题思路很清晰,大概十分钟就想出来规模100000明显复杂度最多nlog所以只能一遍loop然后里利用map统计得到后面的 ...

  4. 【CF】438E. The Child and Binary Tree

    http://codeforces.com/contest/438/problem/E 题意:询问每个点权值在 $c_1, c_2, ..., c_m$ 中,总权值和为 $s$ 的二叉树个数.请给出每 ...

  5. 【CF】148D Bag of mice

    http://codeforces.com/problemset/problem/148/D 题意:w个白b个黑,公主和龙轮流取,公主先取,等概率取到一个.当龙取完后,会等概率跳出一只.(0<= ...

  6. 【CF】328 D. Super M

    这种图论题已经变得简单了... /* D */ #include <iostream> #include <string> #include <map> #incl ...

  7. 【CF】7 Beta Round D. Palindrome Degree

    manacher+dp.其实理解manacher就可以解了,大水题,dp就是dp[i]=dp[i>>1]+1如何满足k-palindrome条件. /* 7D */ #include &l ...

  8. 【CF】86 B. Petr#

    误以为是求满足条件的substring总数(解法是KMP分别以Sbeg和Send作为模式串求解满足条件的position,然后O(n^2)或者O(nlgn)求解).后来发现是求set(all vali ...

  9. 【CF】121 Div.1 C. Fools and Roads

    题意是给定一棵树.同时,给定如下k个查询: 给出任意两点u,v,对u到v的路径所经过的边进行加计数. k个查询后,分别输出各边的计数之和. 思路利用LCA,对cnt[u]++, cnt[v]++,并对 ...

随机推荐

  1. linux中转换编码

    iconv -f gb2312 -t utf-8 文件 -o 输出文件名 iconv -f gb2312 -t utf-8 文件 #直接在终端中显示 enca -L zh_CN file    #查看 ...

  2. jenkins(二)项目构建

    通过上一篇“jenkins(一)集成环境搭建示例”,已经完成了jenkins的安装,基本配置,启动,下面继续小结jenkins使用 一.jenkins系统配置 访问jenkins,点击系统管理-> ...

  3. Xcode7 Xcode6 中添加pch文件

    在Xcode7 和 Xcode6 中添加.pch文件是一样的,具体操作图文如下: 第一步:在Xcode的项目里,一般在Supporting Files 文件夹下创建,选中Supporting File ...

  4. javascript中event.keycode大全

    keycode 8 = BackSpace BackSpace  keycode 9 = Tab Tab  keycode 12 = Clear  keycode 13 = Enter  keycod ...

  5. 关于Spring AOP和IOC的一些总结

    Spring官方网站:https://spring.io/ 最早对象的创建是有new关键字,但是如果产生的类比较繁多或者复杂,就用工厂代替new关键字,但是工厂的控制能力有限,譬如对产生对象的生命周期 ...

  6. javascript 节点的增,删,改,查

    1.创建节点  A.创建元素节点    document.createElement("元素标签名");   B.创建属性节点    document.createAttribut ...

  7. [转载] PowerMokito 使用

    一.为什么要使用Mock工具 在做单元测试的时候,我们会发现我们要测试的方法会引用很多外部依赖的对象,比如:(发送邮件,网络通讯,远程服务, 文件系统等等). 而我们没法控制这些外部依赖的对象,为了解 ...

  8. 简易ORM(基于注解)

    这是从我们现有项目做的一定的改进准备做成IDE插件 类似getter和setter的生成 1.定义实体类 通过注解说明其表名和字段名(SOURCE类型的注解 不需要运行时使用)@TableName(& ...

  9. win7如何完全写在iis

    在前些天,因为需要搭建了ftp服务器,但是今天不需要了,所以要卸载iis,因为我不会让iis和apache同时共存,所以只能卸载了 先找到windows功能,然后把Internet信息服务勾选掉,重启 ...

  10. 如何写一个像btgoogle一样的12306泄露数据查询

    demo地址:http://www.btgoogle.com/12306/ 圣诞节,12306送给了我们一个大礼物.大约 14w的数据泄露, 看网上都沸沸扬扬的.开始也准备找一个数据库来看看,随后,我 ...