이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int W, n;
cin >> W >> n;
vector<array<long long, 2>> a;
for (int i = 0; i < n; i++) {
long long v, w, cnt;
cin >> v >> w >> cnt;
long long coef = 1;
while (coef <= cnt) {
a.push_back({ coef * v, coef * w });
coef *= 2;
}
}
n = a.size();
vector<vector<long long>> dp(n + 1, vector<long long>(W + 1, 0));
for (int i = 1; i <= n; i++) {
for (int w = 0; w <= W; w++) {
if (w - a[i - 1][1] >= 0) {
dp[i][w] = max( dp[i][w], dp[i - 1][w - a[i - 1][1]] + a[i - 1][0] );
}
}
}
cout << *max_element(dp[n].begin(), dp[n].end()) << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |