제출 #975515

#제출 시각아이디문제언어결과실행 시간메모리
975515vjudge1Knapsack (NOI18_knapsack)C++17
49 / 100
166 ms262144 KiB
#include<bits/stdc++.h> using namespace std; #define int long long int s, n, dp[100005][2005] = {0}; signed main(){ cin >> s >> n; if(n == 1){ int v, w, k; cin >> v >> w >> k; if(s / w >= k){ cout << k * v; }else{ cout << (s / w) * v; } return 0; } int idx = 0; for(int x = 1; x <= n; x++){ int v, w, k; cin >> v >> w >> k; for(int i = idx + 1; i <= idx + k; i++){ // cout << i << " -> "; for(int j = 1; j <= s; j++){ dp[i][j] = dp[i - 1][j]; if(w <= j){ dp[i][j] = max(dp[i][j], dp[i - 1][j - w] + v); } // cout << dp[i][j] << ' '; }// cout << endl; } idx += k; } cout << dp[idx][s]; }
#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...