POJ 2533 3903(最长递增子序列)
来源:互联网 发布:神马快递单打印软件 编辑:程序博客网 时间:2024/06/17 12:19
题目链接:http://poj.org/problem?id=2533
题目链接:http://poj.org/problem?id=3903
2533是裸的最长递增子序列。
3903需要用到二分优化,否则至改动2533代码的数组大小是过不了的。
POJ 2533:
#include<iostream>#include<cstdio>#include<string.h>#include<algorithm>using namespace std;const int INF=0x3f3f3f3f;const int maxn=1005;int n;int a[maxn],dp[maxn];int main(){#ifndef ONLINE_JUDGE freopen("test.in","r",stdin); freopen("test.out","w",stdout);#endif while(scanf("%d",&n)!=EOF){ for(int i=1;i<=n;i++) scanf("%d",&a[i]); memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++){ for(int j=1;j<i;j++){ if(a[i]>a[j]&&dp[i]<dp[j]+1){ dp[i]=dp[j]+1; } } } int ans=0; for(int i=1;i<=n;i++) ans=max(dp[i],ans); printf("%d\n",ans+1); }return 0;}
POJ 3903:
#include<iostream>#include<cstdio>#include<string.h>#include<algorithm>using namespace std;const int INF=0x3f3f3f3f;const int maxn=100005;int n;int a[maxn],dp[maxn];int Binary_Search(int *a,int len,int n){int left=0,right=len,mid=(left+right)/2;while(left<=right){if(n>a[mid]) left=mid+1;else if(n<a[mid]) right=mid-1;else return mid;mid=(left+right)/2;}return left;}int main(){#ifndef ONLINE_JUDGE freopen("test.in","r",stdin); freopen("test.out","w",stdout);#endif while(scanf("%d",&n)!=EOF){ for(int i=0;i<n;i++) scanf("%d",&a[i]); dp[0]=-1,dp[1]=a[0]; int len=1; for(int i=1;i<n;i++){ int tmp=Binary_Search(dp,len,a[i]); dp[tmp]=a[i]; if(tmp>len) len=tmp; } printf("%d\n",len); }return 0;}
0 0
- POJ 2533 3903(最长递增子序列)
- POJ 3903 【最长递增子序列 NLOGN】
- poj 2533 最长递增子序列
- POJ 2533 最长递增子序列
- POJ 2533 最长递增子序列
- poj 2533 最长递增子序列
- poj-2533 最长递增子序列
- POJ 2533最长递增子序列O(nlogn) 算法
- poj 2533 Longest Ordered Subsequence(最长递增子序列)
- POJ 2533 Longest Ordered Subsequence(最长递增子序列)
- poj-2533 Longest Ordered Subsequence(最长递增子序列)
- poj 2533 Longest Ordered Subsequence (最长递增子序列)
- POJ 3903-Stock Exchange/POJ 2533-Longest Ordered Subsequence(LIS-最长递增子序列长度)
- POJ 3903 Stock Exchange_LIS(最长递增子序列) 经典例题!
- poj 2533 Longest Ordered Subsequence 最长递增子序列
- poj 2533 Longest Ordered Subsequence (最长递增子序列)
- poj 1631 Bridging signals(最长递增子序列)
- poj 1631Bridging signals Dp(最长递增子序列)
- 构造哈夫曼树的算法
- Spark学习笔记5-隐式转换,隐式参数,隐式类
- 第十章编程练习(3)
- 在Mac系统下安装mongodb两种方式
- 安卓项目中 一些常见 API接口总结
- POJ 2533 3903(最长递增子序列)
- HDU 5601 N*M bulbs
- 微信支付错误两个问题的解决:curl出错,错误码:60
- java替换pdf模板出现中文乱码问题
- HDU 5606 tree
- django学习心得
- C++引用计数(reference counting)技术简介(3)
- Number Sequence
- Json 中对Key为空的判断