题意:求一个波浪子序列,就是是前一半是上升子序列,后一半是下降子序列(子序列的长度必须为奇数)。

分别从左右两个方向求LIS,然后在统计最大值就行了

 //#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<sstream>
#include<cmath>
#include<climits>
#include<string>
#include<map>
#include<queue>
#include<vector>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb(a) push_back(a)
#define INF 0x1f1f1f1f
#define lson idx<<1,l,mid
#define rson idx<<1|1,mid+1,r
#define PI  3.1415926535898
void debug()
{
#ifdef ONLINE_JUDGE
#elsefreopen("d:\\in.txt","r",stdin);// freopen("d:\\out1.txt","w",stdout);
#endif
}
char getch()
{char ch;while((ch=getchar())!=EOF){if(ch!=' '&&ch!='\n')return ch;}return EOF;
}
int dp1[10010],dp2[10010];
int da[10010];
int d[10010];
int work1(int n)
{int maxx=0;for(int i=1;i<=n;i++){int pos=lower_bound(d+1,d+1+maxx,da[i])-d;dp1[i]=pos;d[pos]=da[i];maxx=max(maxx,pos);}return 0;
}
int work2(int n)
{int maxx=0;for(int i=n;i>=1;i--){int pos=lower_bound(d+1,d+1+maxx,da[i])-d;dp2[i]=pos;d[pos]=da[i];maxx=max(maxx,pos);}return 0;
}
int main()
{int n;while(scanf("%d",&n)!=EOF){for(int i=1;i<=n;i++)scanf("%d",&da[i]);int maxx=0;work1(n);work2(n);for(int i=1;i<=n;i++){int x=min(dp1[i],dp2[i]);maxx=max(maxx,x*2-1);}printf("%d\n",maxx);}return 0;
}

View Code

转载于:https://www.cnblogs.com/BMan/p/3250319.html

UVA 10534 Wavio Sequence DP LIS相关推荐

  1. uva 10534——Wavio Sequence

    题意:给定一个序列,求一个最长的序列,使得他的前半部分是递增的,而后半部分是递减的,且两部分的长度一样. 思路:经典的LIS问题,和openjudge登山问题一样,前后各扫一遍,找到前置和倒置的LIS ...

  2. UVA 10534 - Wavio Sequence

    这道题的意思是让我们求一个上升子序列 + 一个下降字序列,且两边的长度是相等的,由于用正常的 O(n2) 算法会 TLE ,所以这里我们采用二分法求最长上升子序列,这里需要利用两个栈来储存" ...

  3. UVA10534 Wavio Sequence【LIS+DP】

    Wavio is a sequence of integers. It has some interesting properties. • Wavio is of odd length i.e. L ...

  4. 【UVa】Wavio Sequence(dp)

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

  5. uva 1626 - Brackets sequence

    // // main.cpp // uva 1626 - Brackets sequence/*这一题应该是经典的矩阵类似问题.显然 需要使用两个变量来表示最终的结果.设 dp[i][j]表示第i个位 ...

  6. 紫书动规 例题9-10 UVA - 1626 Brackets sequence 区间dp

    题目链接: https://vjudge.net/problem/UVA-1626 题意: 题解: dp[i][j]:= i~j需要最少的括号 区间dp: dp[i][j] = min(dp[i][j ...

  7. Brackets sequence UVA - 1626(区间DP)

    题目链接:https://vjudge.net/problem/UVA-1626 题目描述:首先规定了合法的串满足:(1)空字符串是合法的串:(2)若串S是合法的串,则串(S)和 [ S ] 都是合法 ...

  8. UVA 116 Unidirectional TSP DP

    题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&p ...

  9. HDU 4352 数位dp + LIS(nlogn) + 状态压缩

    #define xhxj (Xin Hang senior sister(学姐))  If you do not know xhxj, then carefully reading the entir ...

最新文章

  1. random类的使用
  2. fscanf()函数具体解释
  3. Blend学习资料总结
  4. mysql-5.7.18-winx64 安装 net start mysql 发生系统错误2
  5. 【DB2】NVL2函数
  6. QT学习:线程等待与唤醒
  7. html5做的太阳系
  8. 服务器之Apache和Tomcat和Nginx的理解和对比
  9. 扬帆技术论坛系统封装工具 SPAT v 5.5.3.6_BETA1[官方最新版]
  10. android listview 连续调用 getview问题分析及解决。
  11. 来了!Python 官方发布整套中文PDF文档(共27本)
  12. 抖音时钟js css,JS+CSS3实现时钟效果(抖音)
  13. Simulink入门--创建简单模型
  14. hivesql解析json格式的key与value
  15. C语言刷题随记 —— 国际象棋棋盘
  16. 翻译管理协作翻译平台-crowdin
  17. redis面试:哨兵模式主从切换数据丢失问题
  18. Flak 自定义URL转换器
  19. Solr初探(五)---Solr7.5利用DIH导入结构化数据构建索引
  20. Source Insight 4.0 代码自动排版 2019

热门文章

  1. 邻接矩阵存储图的深度优先遍历
  2. 插值法补齐缺失数据_数据挖掘非常重要的一步:数据预处理
  3. 数据结构-在O(1)时间删除链表节点
  4. 使用pdo,使用pdo无法插入数据怎么办
  5. fiddler抓包工具-- 本地资源替换线上文件
  6. 《DSP using MATLAB》Problem 6.16
  7. PyQt 5.4参考指南 ---- PyQt5和PyQt4之间的差异
  8. 查询屏幕中一个已知颜色的值
  9. 数据科学可视化之要途
  10. win7屏幕录制软件psr.exe使用教程(转)