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.
24 lines
555 B
24 lines
555 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
const int N = 1010;
|
|
int n, m;
|
|
int v[N], w[N];
|
|
int f[N][N];
|
|
|
|
int main() {
|
|
//优化输入
|
|
ios::sync_with_stdio(false);
|
|
//物品个数n
|
|
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 = 1; j <= m; j++)
|
|
if (j >= v[i]) f[i][j] = max(f[i - 1][j], f[i - 1][j - v[i]] + w[i]); //两种情况取最大值
|
|
else f[i][j] = f[i - 1][j];
|
|
|
|
cout << f[n][m] << endl;
|
|
return 0;
|
|
} |