'commit'
This commit is contained in:
27
TangDou/KaoShi/买瓜子.cpp
Normal file
27
TangDou/KaoShi/买瓜子.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int N = 1010;
|
||||
int n, m;
|
||||
int v[N], w[N];
|
||||
int f[N];
|
||||
/**
|
||||
测试用例:
|
||||
80 2
|
||||
18 10
|
||||
30 20
|
||||
*/
|
||||
|
||||
//完全背包问题
|
||||
int main() {
|
||||
cin >> m >> n;
|
||||
for (int i = 1; i <= n; i++) cin >> v[i] >> w[i];
|
||||
|
||||
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] << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user