Login
Register
Problem list
Online status
09021226
:
2023-05-11 16:12:22
#include
using namespace std; int main() { int m, n, c, s, v; cin >> m; for (int i = 0; i < m; i++) { int value[101] = {}; cin >> n >> c; for (int j = 0; j < n; j++) { cin >> s >> v; for (int k = c; k >= 1; k--) { if (s <= k) { value[k] = max(value[k - s] + v, value[k]); } } } cout << value[c] << endl; } }
lin zehao
:
2023-05-04 16:43:39
简洁之美 #include
using namespace std; int main() { int m, n, c, s, v; cin >> m; for (int i = 0; i < m; i++) { int value[101] = {}; cin >> n >> c; for (int j = 0; j < n; j++) { cin >> s >> v; for (int k = c; k >= 1; k--) { if (s <= k) { value[k] = max(value[k - s] + v, value[k]); } } } cout << value[c] << endl; } }
Post Your Comment