제출 #976540

#제출 시각아이디문제언어결과실행 시간메모리
976540vjudge1Knapsack (NOI18_knapsack)C++17
37 / 100
2 ms860 KiB
#include <iostream> #include <algorithm> #include <cstring> #include <vector> using namespace std; typedef long long ll; ll v[10005], w[10005]; ll s, n; ll dp[2][10005]; int main() { cin >> s >> n; ll total = 0; ll idx = 1; while (n--) { ll V, W, K; cin >> V >> W >> K; total += K; ll i = idx; for (; i < idx + K; i++) { v[i] = V; w[i] = W; } idx = i; } memset(dp, 0, sizeof(dp)); for (ll i = 1; i <= total; i++) { for (ll j = 0; j <= s; j++) { ll best = dp[(i - 1) % 2][j]; if (w[i] <= j) { best = max(best, v[i] + dp[(i - 1) % 2][j - w[i]]); } dp[i % 2][j] = best; } } cout << dp[total % 2][s] << endl; }
#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...