hihoCoder 1043 完全背包 (dp)

时间:2021-05-08 13:40:53

http://hihocoder.com/problemset/problem/1043

动态转移方程 :for v=cost..V

        f[v]=max(f[v],f[v-c[i]]+w[i]);

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; int n,m;
int dp[]={};
void CompletePack(int cost,int weight)
{
for(int i=cost;i<=m;i++)
{
dp[i]=max(dp[i],dp[i-cost]+weight);
}
} int main()
{
int a,b;
scanf("%d%d",&n,&m);
for(int i=;i<n;i++)
{
scanf("%d%d",&a,&b);
CompletePack(a,b);
}
printf("%d\n",dp[m]);
return ;
}