【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]++,并对 ...
 
随机推荐
- LSJ_NHibernate第一章 NHibernate介绍
			
前言: 说起NHibernate网上资料真不少,但用的人却并不多,说起java的SSH框架大家可能就知道了,这里的H指的就是Hibernate,一款好用的ORM框架,在.net重写了这款好用的框架,名 ...
 - MVC小系列(十六)【在控制器级别或具体Action级别上动态设定模板页(Layout)】
			
方法就是使用:ActionFilterAttribute它的几个方法:OnActionExecuted,OnActionExecuting,OnResultExecuted和OnResultExecu ...
 - DLL使用总结
			
最近项目中使用到了DLL,因此就把最近一段时间的学习总结一下,以备不时之需. 一.相关概念 1.动态链接库 自从微软推出第一个版本的Windows操作系统以来,动态链接库(DLL)一直是Windows ...
 - Jquery Ajax调用aspx页面实例
			
目前,我会的几种asp.net界面与后台代码交互方式有几种: 1.webform+服务器控件交互: 2.webform+jquery+ajax+一般处理程序交互: 3.webform+jquery+a ...
 - Java Web应用启动间隔执行的程序
			
Reference:<Java定时器timer.schedule在Web中间隔执行任务和定时><[Java]Timer和TimerTask详解> 做了一个Demo,完成如下的功 ...
 - mediawiki数据库的下载地址及导入方法
			
mediawiki导入数据库 数据库下载:http://zh.wikipedia.org/wiki/Wikipedia:%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%8B%E8% ...
 - asp.net:用类来后台绑定数据源
			
//封装成一个 using System;using System.Collections.Generic;using System.Linq;using System.Web;using Syste ...
 - c# 串口发送接收数据
			
/********************** 串口数据接收事件 *****************************/ private void SerialPort_DataReceived ...
 - Dao模型设计(基于Dao与Hebernate框架)
			
以前没有Dao设计模型之前,一般都是这样的流程: ①先设计实体对象 学生对象: package com.itheima.domain; import java.io.Serializable; imp ...
 - bzoj1485:[HNOI2009]有趣的数列
			
思路:首先限制数很多,逐步来考虑,限制一很容易满足,考虑限制二,也就是让奇数位和偶数位上的数递增,限制三就是让奇数位上的数小于奇数位加一对应的偶数位上的数,那么我们可以把形成序列的过程看成加数的过程, ...