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;
}
本文来自博客园,作者:斯文~,转载请注明原文链接:https://www.cnblogs.com/zhiweb/p/15483285.html

浙公网安备 33010602011771号