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 动规 | Read Count: 197

登录 *


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