最长上升子序列
2018-03-09 20:45
176 查看
最长上升子序列
Time Limit: 3000 ms Memory Limit: 65536 KiB
Submit Statistic Discuss
Problem Description
一个数的序列bi,当b1 < b2 < … < bS的时候,我们称这个序列是上升的。对于给定的一个序列(a1, a2, …, aN),我们可以得到一些上升的子序列(ai1, ai2, …, aiK),这里1<= i1 < i2 < … < iK <= N。比如,对于序列(1, 7, 3, 5, 9, 4, 8),有它的一些上升子序列,如(1, 7), (3, 4, 8)等等。这些子序列中最长的长度是4,比如子序列(1, 3, 5, 8)。
你的任务,就是对于给定的序列,求出最长上升子序列的长度。
Input
输入的第一行是序列的长度N (1 <= N <= 1000)。第二行给出序列中的N个整数,这些整数的取值范围都在0到10000。
Output
最长上升子序列的长度。
Sample Input
7
1 7 3 5 9 4 8
Sample Output
4
Hint
Source
Northeastern Europe 2002
Time Limit: 3000 ms Memory Limit: 65536 KiB
Submit Statistic Discuss
Problem Description
一个数的序列bi,当b1 < b2 < … < bS的时候,我们称这个序列是上升的。对于给定的一个序列(a1, a2, …, aN),我们可以得到一些上升的子序列(ai1, ai2, …, aiK),这里1<= i1 < i2 < … < iK <= N。比如,对于序列(1, 7, 3, 5, 9, 4, 8),有它的一些上升子序列,如(1, 7), (3, 4, 8)等等。这些子序列中最长的长度是4,比如子序列(1, 3, 5, 8)。
你的任务,就是对于给定的序列,求出最长上升子序列的长度。
Input
输入的第一行是序列的长度N (1 <= N <= 1000)。第二行给出序列中的N个整数,这些整数的取值范围都在0到10000。
Output
最长上升子序列的长度。
Sample Input
7
1 7 3 5 9 4 8
Sample Output
4
Hint
Source
Northeastern Europe 2002
#include <iostream> #include <stdio.h> using namespace std; const int M = 1005; int main() { int n; scanf("%d", &n); int ar[M]; int br[M]; int i; for(i = 0; i < n; i++) { br[i] = 1; cin >> ar[i]; } for(int i = 1; i < n; i++) { for(int j = 0; j < i; j++) { if(ar[i] > ar[j]) if(br[i] <= br[j])//必须使用<=,因为存在相等的情况 br[i] = br[j] + 1; } } int mmax = br[0]; for(int i = 1; i < n; i++) { if(br[i] > mmax) mmax = br[i]; } cout << mmax << endl; return 0; }
相关文章推荐
- hdu 5773 贪心+最长上升子序列
- SDUt 2028 最长上升子序列
- #10 D. LCIS (dp+最长公共上升子序列)
- HDU - 1096 - Monkey and Banana(最长上升子序列)
- 最长上升子序列问题的几种解法
- BZOJ3173 [Tjoi2013]最长上升子序列
- YTU3135--最长上升子序列(dp)
- 最长公共上升子序列
- C++动态规划算法之最长上升子序列
- 【序列型DP】最长严格上升子序列
- 最长上升子序列&几何题解
- cojs1101. [Vijos1369] 难解的问题==codevs 2188 最长上升子序列
- CSU 1807 最长上升子序列~
- HDU 1160 FatMouse's Speed (最长上升子序列+记录路径)
- B - Almost Sorted Array (最长上升子序列o(nlogn))
- 动规基础,最长上升子序列
- nlog(n)解动态规划--最长上升子序列(Longest increasing subsequence)
- poj2533--Longest Ordered Subsequence(dp:最长上升子序列)
- UVA 10154 Weights and Measures(贪心+DP最长上升子序列)
- 【基础练习】【线性DP】codevs1576 最长严格上升子序列题解