AcWing 3.完全背包问题
题目链接:https://www.acwing.com/problem/content/3/
博客链接:https://www.cnblogs.com/marswithme/p/16737193.html
放AC代码
1 #include<bits/stdc++.h> 2 using namespace std; 3 int n, m; 4 int v[1010], w[1010], dp[1010]; 5 6 int main() 7 { 8 cin >> n >> m; 9 for(int i = 1; i <= n; i ++) 10 cin >> v[i] >> w[i]; 11 for(int i = 1; i <= n; i ++) 12 for(int j = v[i]; j <= m; j++) 13 dp[j] = max(dp[j], dp[j - v[i]] + w[i]); 14 cout << dp[m]; 15 return 0; 16 }