POJ 3903-Stock Exchange/POJ 2533-Longest Ordered Subsequence(LIS-最长递增子序列长度)
来源:互联网 发布:lovelive舞蹈教学 知乎 编辑:程序博客网 时间:2024/05/16 17:12
Stock Exchange
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 6647 Accepted: 2342
Description
The world financial crisis is quite a subject. Some people are more relaxed while others are quite anxious. John is one of them. He is very concerned about the evolution of the stock exchange. He follows stock prices every day looking for rising trends. Given a sequence of numbers p1, p2,...,pn representing stock prices, a rising trend is a subsequence pi1 < pi2 < ... < pik, with i1 < i2 < ... < ik. John’s problem is to find very quickly the longest rising trend.
Input
Each data set in the file stands for a particular set of stock prices. A data set starts with the length L (L ≤ 100000) of the sequence of numbers, followed by the numbers (a number fits a long integer).
White spaces can occur freely in the input. The input data are correct and terminate with an end of file.
White spaces can occur freely in the input. The input data are correct and terminate with an end of file.
Output
The program prints the length of the longest rising trend.
For each set of data the program prints the result to the standard output from the beginning of a line.
For each set of data the program prints the result to the standard output from the beginning of a line.
Sample Input
6 5 2 1 4 5 3 3 1 1 1 4 4 3 2 1
Sample Output
3 1 1
Hint
There are three data sets. In the first case, the length L of the sequence is 6. The sequence is 5, 2, 1, 4, 5, 3. The result for the data set is the length of the longest rising trend: 3.
Source
Southeastern European Regional Programming Contest 2008
两道裸题,求LIS-最长递增子序列长度。
但是POJ 3903数据量需要O(nlogn)复杂度的代码来完成:
#include<iostream>#include<cstdio>#include<iomanip>#include<cmath>#include<cstdlib>#include<cstring>#include<map>#include<algorithm>#include<vector>#include<queue>using namespace std;#define INF 0x3f3f3f3f#define MAXN 100010int a[MAXN],dp[MAXN];int main(){#ifdef ONLINE_JUDGE#else freopen("F:/cb/read.txt","r",stdin); //freopen("F:/cb/out.txt","w",stdout);#endif ios::sync_with_stdio(false); cin.tie(0); int n; while(cin>>n) { for(int i=0; i<n; ++i) cin>>a[i]; fill(dp,dp+n,INF); for(int i=0; i<n; i++) *lower_bound(dp,dp+n,a[i])=a[i]; int ans=lower_bound(dp,dp+n,INF)-dp; cout<<ans<<endl; }}
POJ 2533 用n方复杂度可过:
#include<iostream>#include<cstdio>#include<iomanip>#include<cmath>#include<cstdlib>#include<cstring>#include<map>#include<algorithm>#include<vector>#include<queue>using namespace std;#define INF 0x3f3f3f3f#define MAXN 1100int a[MAXN],dp[MAXN];int main(){#ifdef ONLINE_JUDGE#else freopen("F:/cb/read.txt","r",stdin); //freopen("F:/cb/out.txt","w",stdout);#endif ios::sync_with_stdio(false); cin.tie(0); int n; cin>>n; for(int i=0; i<n; ++i) cin>>a[i]; int res=0; for(int i=0; i<n; ++i) { dp[i]=1; for(int j=0; j<i; ++j) if(a[j]<a[i]) dp[i]=max(dp[i],dp[j]+1); res=max(res,dp[i]); } cout<<res<<endl;}
0 0
- POJ 3903-Stock Exchange/POJ 2533-Longest Ordered Subsequence(LIS-最长递增子序列长度)
- poj 2533 Longest Ordered Subsequence(最长递增子序列)
- POJ 2533 Longest Ordered Subsequence(最长递增子序列)
- poj-2533 Longest Ordered Subsequence(最长递增子序列)
- poj 2533 Longest Ordered Subsequence (最长递增子序列)
- poj 2533 Longest Ordered Subsequence(LIS(最长上升子序列))
- POJ 2533 Longest Ordered Subsequence(LIS:最长上升子序列)
- poj 2533 Longest Ordered Subsequence 最长递增子序列
- poj 2533 Longest Ordered Subsequence (最长递增子序列)
- POJ 2533 Longest Ordered Subsequence (DP,最长递增序列)
- Longest Increasing Subsequence[LIS 最长上升子序列问题] (Longest Ordered Subsequence) POJ
- 【POJ 2533】Longest Ordered Subsequence(最长上升子序列LIS)
- POJ 2533 Longest Ordered Subsequence(最长非递减子序列,LIS)
- poj 2533 Longest Ordered Subsequence (最长子序列)
- poj 2533 Longest Ordered Subsequence(最长上升子序列)
- POJ 2533 Longest Ordered Subsequence(最长上升子序列)
- POJ 2533 Longest Ordered Subsequence(最长上升子序列)
- POJ 2533Longest Ordered Subsequence(最长上升子序列)
- Java中getResourceAsStream的用法
- ubuntu16.0.4安装搜狗输入法
- C++知识点11
- RTMP学习(七)rtmpdump源码阅读(2)与rtmp有关的结构体
- Java连接各种数据库要用到的驱动程序名和URL
- POJ 3903-Stock Exchange/POJ 2533-Longest Ordered Subsequence(LIS-最长递增子序列长度)
- Ubuntu下开启MongoDB用户权限
- 操作系统统计信息v$osstat
- SQL语句创建表并添加数据
- Linux:统计文件词频
- nachos-java Task1.2 Condition Variables
- POJ 3047 Bovine Birthday 再想想
- 并查集的具体例题
- 等待级别和等待事件相关动态性能视图