不需要代码
2024-08-18 15:19:29
发布于:广东
17阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;int n, m;vector<int> weights(1145);vector<int> values(1145);void bag(int n, int m) {vector<int> dp(m + 1, 0);for (int i = 0; i < n; ++i) {int weight = weights[i];int value = values[i]; for (int j = m; j >= weight; --j) dp[j] = max(dp[j], dp[j - weight] + value);}cout << dp[m] << endl; }int main() {cin >> n >> m;for (int i = 0; i < n; ++i) cin >> weights[i];for (int i = 0; i < n; ++i) cin >> values[i];bag(n, m);return 0;}
这里空空如也
有帮助,赞一个