✅ 完全背包问题模版
This commit is contained in:
parent
c648a9cabb
commit
63e337e067
19
complete-backup/main.cc
Normal file
19
complete-backup/main.cc
Normal file
@ -0,0 +1,19 @@
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
#define MAXN 10005
|
||||
#define M 105
|
||||
int dp[MAXN];
|
||||
int w[M], v[M];
|
||||
int x[M];
|
||||
int main() {
|
||||
int n, W;
|
||||
cin >> W >> n;
|
||||
for (int i = 1; i <= n; i++)
|
||||
cin >> w[i] >> v[i];
|
||||
for (int i = 1; i <= n; i++)
|
||||
for (int j = w[i]; j <= W; j++)
|
||||
dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
|
||||
cout << dp[W] << endl;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user