제출 #887699

#제출 시각아이디문제언어결과실행 시간메모리
887699votranngocvyKnapsack (NOI18_knapsack)C++14
73 / 100
181 ms4104 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 1e5 + 5; int dp[105][2005],w[N],v[N],k[N]; 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]; if (n <= 100) { int ans = 0; for (int i = 1; i <= n; i++) for (int j = 0; j <= s; j++) { dp[i][j] = max(dp[i][j],dp[i - 1][j]); for (int z = 1; z <= min(s / w[i],k[i]); z++) if (j + w[i] * z <= s) dp[i][j + w[i] * z] = max(dp[i][j + w[i] * z],dp[i - 1][j] + v[i] * z); ans = max(ans,dp[i][j]); } 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...