码迷,mamicode.com
首页 > 其他好文 > 详细

POJ2533——Longest Ordered Subsequence(简单的DP)

时间:2014-10-30 16:56:36      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   io   color   os   ar   for   sp   

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
7
1 7 3 5 9 4 8
Sample Output
4

题目大意:

    给定一个数列,输出其最长递增子序列的长度。

解题思路:

    水题,不解释。

Code:

 1 /*************************************************************************
 2     > File Name: poj2533.cpp
 3     > Author: Enumz
 4     > Mail: 369372123@qq.com
 5     > Created Time: 2014年10月27日 星期一 20时07分22秒
 6  ************************************************************************/
 7 
 8 #include<iostream>
 9 #include<cstdio>
10 #include<cstdlib>
11 #include<string>
12 #include<cstring>
13 #include<list>
14 #include<queue>
15 #include<stack>
16 #include<map>
17 #include<set>
18 #include<algorithm>
19 #include<cmath>
20 #include<bitset>
21 #include<climits>
22 #define MAXN 1001
23 using namespace std;
24 int date[MAXN];
25 int dp[MAXN];
26 int main()
27 {
28     int N;
29     while (cin>>N)
30     {
31         for (int i=1;i<=N;i++)
32             cin>>date[i];
33         for (int i=1;i<=MAXN-1;i++)
34             dp[i]=1;
35         int Max=1;
36         for (int i=2;i<=N;i++)
37         {
38             for (int j=1;j<=i-1;j++)
39                 if (date[j]<date[i])
40                     dp[i]=max(dp[i],dp[j]+1);
41             Max=max(Max,dp[i]);
42         }
43         cout<<Max<<endl;
44     }
45     return 0;
46 }

 

POJ2533——Longest Ordered Subsequence(简单的DP)

标签:des   style   blog   io   color   os   ar   for   sp   

原文地址:http://www.cnblogs.com/Enumz/p/4062934.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!