http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1475

正反一次lis然后去min{左,右}*2-1即可

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define mkpii make_pair<int, int>
#define pdi pair<double, int>
#define mkpdi make_pair<double, int>
#define pli pair<ll, int>
#define mkpli make_pair<ll, int>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define error(x) (!(x)?puts("error"):0)
#define printarr2(a, b, c) for1(_, 1, b) { for1(__, 1, c) cout << a[_][__]; cout << endl; }
#define printarr1(a, b) for1(_, 1, b) cout << a[_] << '\t'; cout << endl
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const int N=10005;
int n, a[N], g[N], f[N], h[N]; void lis() {
CC(g, 0x3f);
for1(i, 1, n) {
int t=lower_bound(g+1, g+1+i, a[i])-g;
f[i]=t;
g[t]=a[i];
}
CC(g, 0x3f);
for3(i, n, 1) {
int t=lower_bound(g+1, g+1+i, a[i])-g;
h[i]=t;
g[t]=a[i];
}
} int main() {
while(~scanf("%d", &n)) {
for1(i, 1, n) read(a[i]);
lis();
int ans=0;
for1(i, 1, n) ans=max(ans, min(f[i], h[i])*2-1);
printf("%d\n", ans);
}
return 0;
}

  

【UVa】Wavio Sequence(dp)的更多相关文章

  1. CJOJ 1071 【Uva】硬币问题(动态规划)

    CJOJ 1071 [Uva]硬币问题(动态规划) Description 有n种硬币,面值分别为v1, v2, ..., vn,每种都有无限多.给定非负整数S,可以选用多少个硬币,使得面值之和恰好为 ...

  2. 【arc074e】RGB Sequence(动态规划)

    [arc074e]RGB Sequence(动态规划) 题面 atcoder 洛谷 翻译见洛谷 题解 直接考虑暴力\(dp\),设\(f[i][j][k][l]\)表示当前考虑到第\(i\)位,最后一 ...

  3. 【arc071f】Infinite Sequence(动态规划)

    [arc071f]Infinite Sequence(动态规划) 题面 atcoder 洛谷 题解 不难发现如果两个不为\(1\)的数连在一起,那么后面所有数都必须相等. 设\(f[i]\)表示\([ ...

  4. 【UVa】Palindromic Subsequence(dp+字典序)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=465&page=s ...

  5. 【ZJOI2017 Round1练习】D8T2 sequence(DP)

    题意: 思路: #include <algorithm> #include <iostream> #include <cstring> #include <c ...

  6. 【ARC064-F】【XSY2575】Rotated Palindromes(DP)(字符串)

    Description 然而,由于小C沉迷于制作游戏,他完全忘记了自己作为国家集训队的一员,还有156道作业题等他完成.还有一天作业就要截止了,而他一题还没有做.于是他赶紧挑了一道看起来最简单的题: ...

  7. 【HDU-6146】Pokémon GO(dp)

    百度之星2017复赛1003 HDU-6146 Pokémon GO 题意 两行n列,只能到相邻格子,可以斜着.求遍历的方案数. 题解 dp[i]从一个点出发遍历长度i最后回到这一列的方案数 dp2[ ...

  8. 【CF1027E】Inverse Coloring(DP)

    题意:给出一个n*n的矩阵,要求在每个位置涂上黑/白色, 要求满足:任意相邻的两行,其颜色要么完全相同,要么完全相反 任意相邻的两列,其颜色也要么相同要么完全相反 且这个矩形中,不存在任意一个大小大于 ...

  9. 【P2401】不等数列(DP)

    这个题乍一看就应该是DP,再看一眼数据范围,1000..那就应该是了.然后就向DP的方向想,经过对小数据的计算可以得出,如果我们用f[i][j]来表示前i个数有j个是填了"<" ...

随机推荐

  1. [Unity3D]Unity3D游戏开发之异步记载场景并实现进度条读取效果

    大家好,我是秦元培.欢迎大家关注我的博客,我的博客地址是:blog.csdn.net/qinyuanpei.终于在各种无语的论文作业中解脱了,所以立即抓紧时间来这里更新博客.博主本来计划在Unity3 ...

  2. excel 获取中文拼音首字母

      excel 获取中文拼音首字母 CreateTime--2018年5月31日08:50:42 Author:Marydon 1.情景展示 想要获取姓名的拼音首字母 2.实现方式 通过使用excel ...

  3. How to authenticate a user by uid and password?

    原文地址:Authentication options | Basic authorization If you want to use simple binds with user DN and p ...

  4. mysql 如何查看sql语句执行时间

    查看执行时间 1 show profiles; 2 show variables;查看profiling 是否是on状态: 3 如果是off,则 set profiling = 1: 4 执行自己的s ...

  5. 【LeetCode】69. Sqrt(x) (2 solutions)

    Sqrt(x) Implement int sqrt(int x). Compute and return the square root of x. 解法一:牛顿迭代法 求n的平方根,即求f(x)= ...

  6. EMQ 注意事项

    ClientID 唯一:否则后连接的会将前面的踢下去 发送的消息内容太长(payload),导致客户端断线,原因是EMQ默认的消息长度是64K(65536字节),一旦超过就会出问题.可能出现场景: 日 ...

  7. SDK Manager 闪退的解决方式

    打开电脑的执行  也就是win+R键    然后在命令行里面打上android即可了

  8. struts2 s:set标签

    set标签是将某个值放到指定范围内, 比如说 student.teacher.parent.age 每次访问这个属性不仅性能低,而且代码可读性很差,为了解决这个问题,可以将这个值设置为一个新值,并且放 ...

  9. hibernate 中集合的保存

    一.开发流程 1)引入jar包,注意引入数据库驱动包 2)创建数据库表 //创建用户表 CREATE TABLE USER( id INT PRIMARY KEY AUTO_INCREMENT, un ...

  10. 常用有话帧检测技术(VAD)

    作者:桂. 时间:2017-05-31  17:43:22 链接:http://www.cnblogs.com/xingshansi/p/6925355.html 前言 总结一下基本的有话帧检测(Vo ...