You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
505 B
25 lines
505 B
#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;
|
|
} |