제출 #690399

#제출 시각아이디문제언어결과실행 시간메모리
690399vjudge1Knapsack (NOI18_knapsack)C++17
0 / 100
1 ms340 KiB
#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; for (int k = 0; k < 31; k++) { if (cnt >> k & 1) { long long coef = (1 << k); a.push_back({ coef * v, coef * w }); } } } 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...