제출 #1212641

#제출 시각아이디문제언어결과실행 시간메모리
1212641LinkedArrayKnapsack (NOI18_knapsack)C++17
17 / 100
1 ms328 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define int ll // 2 ^ 10 ~= 10 ^ 3 => 2 ^ 30 > 10 ^ 9 const int MAX_N = 1e5, MAX_S = 2e3, MAX_K = 1e9, MAX_K_BIT = 30; int v[MAX_N + 1], wi[MAX_N + 1], k[MAX_N + 1]; vector<pair<int, int>> items; int dp[MAX_S + 1]; signed main () { ios_base::sync_with_stdio(false); cin.tie(nullptr); int s, n, i, j, w, new_w, put2; cin >> s >> n; for (i = 1; i <= n; i++) { cin >> v[i] >> wi[i] >> k[i]; put2 = 1; while (k[i] > 0) { k[i] -= put2; items.push_back(make_pair(wi[i] * put2, v[i] * put2)); put2 *= 2; } } // bounded for (auto [item_w, item_v] : items) { // cout << "[" << item_w << ", " << item_v << "]\n"; for (w = s; w >= 0; w--) { new_w = w + item_w; if (new_w <= s) { dp[new_w] = max(dp[new_w], dp[w] + item_v); } } } cout << dp[s]; return 0; }
#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...