【CF】323 Div2. D. Once Again...
挺有意思的一道题目。
考虑长度为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...的更多相关文章
- 【CF】135 Div2 Choosing Capital for Treeland
树形结构,挺有意思的题目.不难. /* 219D */ #include <iostream> #include <string> #include <map> # ...
- 【转载】#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 ...
- 【Codeforces】383.DIV2
昨天一场CF发挥不好.抽点时间总结一下,然后顺带算是做个题解. 第一题水题 第二题思路很清晰,大概十分钟就想出来规模100000明显复杂度最多nlog所以只能一遍loop然后里利用map统计得到后面的 ...
- 【CF】438E. The Child and Binary Tree
http://codeforces.com/contest/438/problem/E 题意:询问每个点权值在 $c_1, c_2, ..., c_m$ 中,总权值和为 $s$ 的二叉树个数.请给出每 ...
- 【CF】148D Bag of mice
http://codeforces.com/problemset/problem/148/D 题意:w个白b个黑,公主和龙轮流取,公主先取,等概率取到一个.当龙取完后,会等概率跳出一只.(0<= ...
- 【CF】328 D. Super M
这种图论题已经变得简单了... /* D */ #include <iostream> #include <string> #include <map> #incl ...
- 【CF】7 Beta Round D. Palindrome Degree
manacher+dp.其实理解manacher就可以解了,大水题,dp就是dp[i]=dp[i>>1]+1如何满足k-palindrome条件. /* 7D */ #include &l ...
- 【CF】86 B. Petr#
误以为是求满足条件的substring总数(解法是KMP分别以Sbeg和Send作为模式串求解满足条件的position,然后O(n^2)或者O(nlgn)求解).后来发现是求set(all vali ...
- 【CF】121 Div.1 C. Fools and Roads
题意是给定一棵树.同时,给定如下k个查询: 给出任意两点u,v,对u到v的路径所经过的边进行加计数. k个查询后,分别输出各边的计数之和. 思路利用LCA,对cnt[u]++, cnt[v]++,并对 ...
随机推荐
- 使用ROW_NUMBER进行的快速分页
DECLARE @pageSize INT ; DECLARE @pageIndex INT ; SET @pageSize = 5 SET @pageIndex =2 ; --第二页,每页显示5条数 ...
- primefaces 带参数的组件
分析了一下primefaces extension showcase的源码,总结一下组件传参的方式. 下面定义了一个组件,名为fourTabsDecoratorCustom.xhtml 1: < ...
- C#创建微信自定义菜单
string posturl = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + access_to ...
- c#对象初始化
class test:IEquatable<test> { public int aa { get; set; } public string bb { get; set; } publi ...
- web.xml配置中的 文件类型<mime-mapping>
<mime-mapping> <extension>doc</extension> <mime-type>application/msword</ ...
- (poj) 1751 Highways
Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has a very poor ...
- Python3 函数式编程
函数式编程就是一种抽象程度很高的编程范式,纯粹的函数式编程语言编写的函数没有变量,因此,任意一个函数,只要输入是确定的,输出就是确定的,这种纯函数我们称之为没有副作用.而允许使用变量的程序设计语言,由 ...
- Extjs发票管理系统
技术特点:Extjs框架,三层架构,Ajax,json 1.仿office2007菜单.介面美观大方,可动态更改皮肤保存至cookie. 2,json数据源与实体类的相互转换. 3.可下载桌面版登录方 ...
- js 中对象属性特性2
对象的存储描述: get 和 set 方法 <script> var obj ={ get age(){ return 22 }, set age(value){ console. ...
- J2EE中的HttpSession
J2EE中的HttpSession总结: ①什么是session? session是服务器端技术,利用这个技术,服务器在运行时可以为每一个浏览器创建一个共享的session对象,由于 session为 ...