hihoCoder week7 完全背包

时间:2021-02-12 00:06:18

完全背包

题目链接 https://hihocoder.com/contest/hiho7/problem/1

#include <bits/stdc++.h>
using namespace std; const int N = + ;
int need[N], value[N]; int dp[+]; int main ()
{
int n,V;
scanf("%d %d", &n, &V);
for(int i=;i<=n;i++)
scanf("%d %d", &need[i], &value[i]);
for(int i=;i<=n;i++) {
for(int j=need[i]; j<=V; j++) {
dp[j] = max(dp[j], dp[j-need[i]] +value[i]);
}
}
cout << dp[V] <<endl;
return ;
}