제출 #887702

#제출 시각아이디문제언어결과실행 시간메모리
887702votranngocvyKnapsack (NOI18_knapsack)C++14
49 / 100
1087 ms2544 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 1e5 + 5; int w[N],v[N],k[N]; vector<int>dp_before(2005,0),dp_cur(2005,0); signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,s; cin >> s >> n; for (int i = 1; i <= n; i++) cin >> v[i] >> w[i] >> k[i]; int ans = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= s; j++) { dp_cur[j] = max(dp_cur[j],dp_before[j]); for (int z = 1; z <= min(s / w[i],k[i]); z++) if (j + w[i] * z <= s) dp_cur[j + w[i] * z] = max(dp_cur[j + w[i] * z],dp_before[j] + v[i] * z); ans = max(ans,dp_cur[j]); } dp_before = dp_cur; } cout << ans << "\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...