7
7
2015
0

bzoj 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛

裸的LIS。

代码:

#include<cstdio>
#include<algorithm>
using namespace std;

int a[5010],f[5010],n;

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	f[1]=1;
	for(int i=2;i<=n;i++){
		for(int j=i-1;j>=1;j--){
			if(a[j]<a[i]){
				f[i]=max(f[i],f[j]);
			}
		}
		f[i]++;
	}
	int mx=0;
	for(int i=1;i<=n;i++){
		mx=max(mx,f[i]);
	}
	printf("%d",mx);
	return 0;
}
Category: 动态规划 | Tags: bzoj 动态规划 | Read Count: 336

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com