51Nod - 2649 完全背包

https://vjudge.net/problem/51Nod-2649

模板题

#include<iostream>
#include<algorithm>
#include<cstring>
#define open ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
using namespace std;
const int N=110,M=50010;
int n,m;
int w[N],v[N];
int f[M];
int main()
{
	open;
	while(cin>>n>>m)
	{
		for(int i=1;i<=n;i++) cin>>v[i]>>w[i];
		
		memset(f,0,sizeof f);
		for(int i=1;i<=n;i++)
			for(int j=v[i];j<=m;j++)
				f[j]=max(f[j],f[j-v[i]]+w[i]);
				
		cout<<f[m]<<"\n";
	}
	return 0;
}
posted @ 2021-07-30 10:49  斯文~  阅读(24)  评论(0)    收藏  举报

你好!