Longest Ordered Subsequence
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 55490 Accepted: 24881

Description

A numeric sequence of a is ordered if a < a < ... < a. Let the subsequence of the given numeric sequence (aa, ..., a) be any sequence (aa, ..., a), where 1 <= i < i < ... < i <= 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

Source

Northeastern Europe 2002, Far-Eastern Subregion
 
  • 简单LIS
 #include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
typedef long long LL ;
typedef unsigned long long ULL ;
const int maxn = + ;
const int inf = 0x3f3f3f3f ;
const int npos = - ;
const int mod = 1e9 + ;
const int mxx = + ;
const double eps = 1e- ;
const double PI = acos(-1.0) ; int a[maxn], dp[maxn], ans, n;
int main(){
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
while(~scanf("%d",&n)){
ans=;
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
dp[i]=;
for(int j=i-;j>;j--)
if(a[i]>a[j])
dp[i]=max(dp[i],dp[j]+);
ans=max(ans,dp[i]);
}
printf("%d\n",ans);
}
return ;
}
05-11 19:23
查看更多