POJ-2533 Longest Ordered Subsequence LIS

  题目链接:http://poj.org/problem?id=2533

  基本DP:f[i]=max{f[j]}+1。

 1 //STATUS:C++_AC_32MS_184KB
 2 #include<stdio.h>
 3 #include<stdlib.h>
 4 #include<string.h>
 5 #include<math.h>
 6 #include<iostream>
 7 #include<string>
 8 #include<algorithm>
 9 #include<vector>
10 #include<queue>
11 #include<stack>
12 using namespace std;
13 #define LL __int64
14 #define pii pair<int,int>
15 #define Max(a,b) ((a)>(b)?(a):(b))
16 #define Min(a,b) ((a)<(b)?(a):(b))
17 #define mem(a,b) memset(a,b,sizeof(a))
18 #define lson l,mid,rt<<1
19 #define rson mid+1,r,rt<<1|1
20 const int N=1010,INF=0x3f3f3f3f,MOD=1999997;
21 const LL LLNF=0x3f3f3f3f3f3f3f3fLL;
22 
23 int num[N],w[N],f[N];
24 int n;
25 
26 int main()
27 {
28  //   freopen("in.txt","r",stdin);
29     int i,j,ans;
30     while(~scanf("%d",&n))
31     {
32         ans=f[0]=1;
33         for(i=0;i<n;i++)
34             scanf("%d",&num[i]);
35         for(i=1;i<n;i++){
36             f[i]=1;
37             for(j=0;j<i;j++)
38                 if(num[j]<num[i])
39                     f[i]=Max(f[i],f[j]+1);
40             if(f[i]>ans)ans=f[i];
41         }
42 
43         printf("%d\n",ans);
44     }
45     return 0;
46 }

 

posted @ 2013-01-20 01:43  zhsl  阅读(168)  评论(0编辑  收藏  举报