poj 2533 Longest Ordered Subsequence
2016-07-27 23:31
423 查看
Longest Ordered Subsequence
Description
A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1, a2, ..., aN)
be any sequence (ai1, ai2, ..., aiK), where 1 <= i1 < i2 < ... < iK <= N. For example, sequence
(1, 7, 3, 5, 9, 4, 8) has ordered subsequences, e. g., (1, 7), (3, 4, 8) and many others. All longest ordered subsequences are of length 4, e. g., (1, 3, 5, 8).
Your program, when given the numeric sequence, must find the length of its longest ordered subsequence.
Input
The first line of input file contains the length of sequence N. The second line contains the elements of sequence - N integers in the range from 0 to 10000 each, separated by spaces. 1 <= N <= 1000
Output
Output file must contain a single integer - the length of the longest ordered subsequence of the given sequence.
Sample Input
Sample Output
4
最大公共子串原题
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 46180 | Accepted: 20509 |
A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1, a2, ..., aN)
be any sequence (ai1, ai2, ..., aiK), where 1 <= i1 < i2 < ... < iK <= N. For example, sequence
(1, 7, 3, 5, 9, 4, 8) has ordered subsequences, e. g., (1, 7), (3, 4, 8) and many others. All longest ordered subsequences are of length 4, e. g., (1, 3, 5, 8).
Your program, when given the numeric sequence, must find the length of its longest ordered subsequence.
Input
The first line of input file contains the length of sequence N. The second line contains the elements of sequence - N integers in the range from 0 to 10000 each, separated by spaces. 1 <= N <= 1000
Output
Output file must contain a single integer - the length of the longest ordered subsequence of the given sequence.
Sample Input
7 1 7 3 5 9 4 8
Sample Output
4
最大公共子串原题
#include <iostream> #include <cstdio> #include <cstring> using namespace std; int main() { int n; int a[1005], dp[1005]; scanf("%d",&n); int i; for(i=0; i<n; i++) { scanf("%d", &a[i]); dp[i]=0; } dp[0]=1; int y=dp[0]; for(i=1; i<n; i++) { int j, ma=0; for(j=i-1; j>=0; j--) { if(a[j]<a[i] &&dp[j]>ma)ma=dp[j]; } dp[i]=ma+1; // printf("%d ", dp[i]); if(dp[i]>y)y=dp[i]; } printf("%d\n", y); return 0; }
相关文章推荐
- Error:Jack is required to support java 8 language features. Either enable Jack or remove sourceCompa
- webpack-dev-server+vue构建开发环境(一)
- ios 不能点击UITableViewCell里的控件
- UIStackView 看我就够了
- Fluent Interface(流式接口)
- 使用 setuid、setgid 和 Sticky 位的特殊文件权限
- [置顶]Request 和 Response 原理
- 关于监听(安卓)
- 关于新导入java项目后提示:Configure build path
- android UI基本控件
- HDU4027:Can you answer these queries?(线段树 单点更新 区间求和)
- unique函数的使用
- poj 2299 Ultra-QuickSort
- 【POJ2299】Ultra-Quicksort-逆序对
- Codeforces670E. Correct Bracket Sequence Editor
- DualPivotQuicksort两枢轴快速排序
- Android Bluetooth(蓝牙)实例
- mysql生成不重复随机数(unique number generation)
- Vue 经验总结
- UITableView全面解析文章