'commit'
This commit is contained in:
25
TangDou/KaoShi/完全背包.cpp
Normal file
25
TangDou/KaoShi/完全背包.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int N = 1010;
|
||||
|
||||
int n, m;
|
||||
int v[N];
|
||||
int w[N];
|
||||
int f[N];
|
||||
|
||||
// 完全背包问题
|
||||
int main() {
|
||||
//优化输入
|
||||
ios::sync_with_stdio(false);
|
||||
cin >> n >> m;
|
||||
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