UVA10534-Wavio Sequence(LIS)
来源:互联网 发布:javascript 第7版 pdf 编辑:程序博客网 时间:2024/05/16 23:37
题目链接
http://acm.hust.edu.cn/vjudge/problem/19219
思路
只需正向和逆向分别做一次LIS,然后ans = 2 * min(d1[i], d2[i]) - 1
代码
#include <iostream>#include <cstring>#include <stack>#include <vector>#include <set>#include <map>#include <cmath>#include <queue>#include <sstream>#include <iomanip>#include <fstream>#include <cstdio>#include <cstdlib>#include <climits>#include <deque>#include <bitset>#include <algorithm>using namespace std;#define PI acos(-1.0)#define LL long long#define PII pair<int, int>#define PLL pair<LL, LL>#define mp make_pair#define IN freopen("in.txt", "r", stdin)#define OUT freopen("out.txt", "wb", stdout)#define scan(x) scanf("%d", &x)#define scan2(x, y) scanf("%d%d", &x, &y)#define scan3(x, y, z) scanf("%d%d%d", &x, &y, &z)#define sqr(x) (x) * (x)#define pr(x) cout << #x << " = " << x << endl#define lc o << 1#define rc o << 1 | 1#define pl() cout << endl#define CLR(a, x) memset(a, x, sizeof(a))#define FILL(a, n, x) for (int i = 0; i < n; i++) a[i] = xconst int maxn = 10000 + 5;int n, d1[maxn], d2[maxn], a[maxn], g1[maxn], g2[maxn];int main() { while (~scan(n)) { for (int i = 0; i < n; i++) scan(a[i]); for (int i = 1; i <= n; i++) g1[i] = INT_MAX; for (int i = 0; i < n; i++) { int k = lower_bound(g1 + 1, g1 + 1 + n, a[i]) - g1; d1[i] = k; g1[k] = a[i]; } for (int i = 1; i <= n; i++) g2[i] = INT_MAX; for (int i = n - 1; i >= 0; i--) { int k = lower_bound(g2 + 1, g2 + 1 + n, a[i]) - g2; d2[i] = k; g2[k] = a[i]; } int res = 1; for (int i = 0; i < n; i++) { int t = 2 * min(d1[i], d2[i]) - 1; res = max(res, t); } printf("%d\n", res); } return 0;}
0 0
- UVA10534-Wavio Sequence(LIS)
- UVA10534-----Wavio Sequence-----动态规划之LIS
- UVA10534[Wavio Sequence] 动态规划 LIS
- Wavio Sequence UVA10534
- UVA10534 wavio sequence
- UVA10534 Wavio Sequence
- uva10534---Wavio Sequence
- UVa10534 Wavio Sequence
- UVa10534 Wavio Sequence
- UVA10534 - Wavio Sequence - 动态规划
- UVA10534 Wavio Sequence(二分 + 最长上升子序列)
- UVa 10534 Wavio Sequence (LIS、LDS)
- UVA - 10534Wavio Sequence(LIS)
- UVA 10534Wavio Sequence(LIS)
- UVA 10534 Wavio Sequence(LIS)
- UVA 10534-Wavio Sequence(LIS)
- HOJ 2085 Wavio Sequence(双lis)
- uva 10534 Wavio Sequence (LIS)
- C++中Static作用和使用方法
- 10.ThreeJs开发指南-第十章-加载和使用纹理
- Combination Sum IV
- 页面置换算法
- 全国各省一本和二本录取率2014年,用事实说话
- UVA10534-Wavio Sequence(LIS)
- 重写NavigationControllerde的一个具体事例
- Swift开发-提示版本更新
- SQL逻辑查询语句执行顺序
- Jstl <fmt:formatDate> problem
- jquery 父、子页面之间页面元素的获取,方法的调用
- JavaScript-瀑布流布局
- java线程池的使用
- 图 —— 特殊状态下的讨论