3
11
2015
0

COGS 588 [NOIP1999]拦截导弹

#include <cstdio>
#include <algorithm>
using namespace std;
int n,f[1001],a[1001];
int main()
{
	//freopen("missile.in","r",stdin);
	//freopen("missile.out","w",stdout);
	while (scanf("%d",&a[++n])>0);
	--n; f[1]=1; int ans=0;
	for (int i=2;i<=n;++i){//最长不下降子序列
		f[i]=1;
		for (int j=1;j<i;++j)
			if (a[j]>=a[i]) f[i]=max(f[i],f[j]+1);
		ans=max(ans,f[i]);
	}
	printf("%d\n",ans); ans=0;
	for (int i=2;i<=n;++i){//最长上升子序列
		f[i]=1;
		for (int j=1;j<i;++j)
			if (a[j]<a[i]) f[i]=max(f[i],f[j]+1);
			ans=max(ans,f[i]);
	}
	printf("%d\n",ans);
	return 0;
}
Category: 题解 | Tags: NOIP COGS 动规 | Read Count: 200

登录 *


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