3
31
2015
0

Tyvj 1005 采药

 

#include <iostream>
using namespace std;
int t,m,f[1001],w[101],v[101];
int main()
{
	cin>>t>>m;
	for (int i=1;i<=m;++i)
		cin>>w[i]>>v[i];
	for (int i=1;i<=m;++i)
		for (int j=t;j>=w[i];--j)
			if (f[j]<f[j-w[i]]+v[i])
				f[j]=f[j-w[i]]+v[i];
	cout<<f[t];
	return 0;
}
Category: 题解 | Tags: Tyvj 动规
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 动规

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