51Nod - 1086 背包问题 V2

https://vjudge.net/problem/51Nod-1086
多重背包模板题

#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],s[N];
int f[N][M];
int main()
{
//	open;
	while(cin>>n>>m)
	{
		for(int i=1;i<=n;i++) cin>>v[i]>>w[i]>>s[i];
		
		memset(f,0,sizeof f);
		for(int i=1;i<=n;i++)
			for(int j=0;j<=m;j++)
				for(int k=0;k<=s[i] && k*v[i]<=j;k++)
					f[i][j]=max(f[i][j],f[i-1][j-k*v[i]]+k*w[i]);
		cout<<f[n][m]<<"\n";
	}
	return 0;
}
posted @ 2021-07-30 10:43  斯文~  阅读(13)  评论(0)    收藏  举报

你好!