POJ3903(dp最长上升子序列STL)
来源:互联网 发布:linux编辑保存命令 编辑:程序博客网 时间:2024/06/04 01:31
题意:看样例就知道。
思路:dp[i]的状态是长度为i+1的上升子序列中最小的值。
这里用到了STL lower_bound头文件是“algorithm”,函数lower_bound()在first和last中的前闭后开区间进行二分查找,返回大于或等于val的第一个元素位置。如果所有元素都小于val,则返回last的位置
#include<iostream>#include<cstring>#include<algorithm>#include<cstdio>using namespace std;#define inf 0x3f3f3f3fint dp[100010];int a[100010];int main(){ //freopen("in.txt","r",stdin); int n; while(scanf("%d",&n) != EOF){ memset(dp,inf,sizeof(dp)); for(int i = 0;i < n; i++){ scanf("%d",&a[i]); } for(int i = 0;i < n; i++){ *lower_bound(dp,dp+n,a[i]) = a[i]; //其实就是找到a[i]属于自己的位置 } printf("%d\n",lower_bound(dp,dp+n,inf)-dp); //很巧妙 } return 0;}
0 0
- POJ3903(dp最长上升子序列STL)
- POJ3903(dp,最长上升子序列,最基础题)
- POJ3903 Stock Exchange 最长上升子序列DP]
- poj3903 Stock Exchange(最长上升子序列)
- 最长上升子序列--poj2533、poj3903、hdu1025
- poj3903--Stock Exchange--nlogn贪心求最长上升子序列
- poj 2533 poj3903 poj1836 最长上升子序列 LIS
- 最长上升子序列 (dp)
- 最长公共上升子序列 (dp)
- 最长上升子序列(DP)
- HDU1087(最长上升子序列DP)
- 最长上升子序列LIS(dp)
- 最长上升子序列(DP+模板)
- YTU3135--最长上升子序列(dp)
- 最长上升子序列(dp)
- 最长公共上升子序列(dp)
- 最长上升子序列(DP)
- 最长上升子序列(Dp)
- Oracle建立表空间和用户
- 极光推送JPush java服务端代码
- Linux虚拟机mysql连接数太多
- 链表 带表头 循环
- cat命令
- POJ3903(dp最长上升子序列STL)
- Glide使用详解
- jquery的样式操作,类操作(添加 删除 css)
- 数据结构实验之排序七:选课名单(卡内存的一道题。。坑)
- Codeforces 368C Sereja and Algorithm【思维】
- 接口
- 修改mysql数据库密码
- c/c++指针详解(二)----内存分配
- shell脚本的一些基础信息