bzoj1669[Usaco2006 Oct]Hungry Cows饥饿的奶牛*

bzoj1669[Usaco2006 Oct]Hungry Cows饥饿的奶牛

题意:

求最长单调递增子序列,序列大小≤5000

题解:

蒟蒻弱写了一个O(n^2)的。

代码:

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define inc(i,j,k) for(int i=j;i<=k;i++)
 5 #define maxn 5100
 6 using namespace std;
 7 
 8 inline int read(){
 9     char ch=getchar(); int f=1,x=0;
10     while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
11     while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
12     return f*x;
13 }
14 int a[maxn],f[maxn],n;
15 int main(){
16     n=read(); inc(i,1,n)a[i]=read();
17     inc(i,1,n){
18         f[i]=1; inc(j,1,i-1)if(a[j]<a[i])f[i]=max(f[i],f[j]+1);
19     }
20     inc(i,1,n)f[0]=max(f[0],f[i]); printf("%d",f[0]); return 0;
21 }

 

20160808

posted @ 2016-08-13 10:12  YuanZiming  阅读(216)  评论(0编辑  收藏  举报