제출 #484683

#제출 시각아이디문제언어결과실행 시간메모리
484683NcodeKnapsack (NOI18_knapsack)C++17
0 / 100
331 ms259688 KiB
#include <bits/stdc++.h> using namespace std; int dp[20005][20005]; const int inf = 1e9+5; int main(){ int S, n; cin>>S>>n; int v, w, k; vector<pair<int, int>> a; for(int i=0;i<n;i++){ cin>>v>>w>>k; while(k--) a.push_back({v, w}); } // for(int i=0;i<n;i++){ // for(int j=0;j<=S;j++){ // dp[i][j] = inf; // } // } dp[0][0] = 0; for(int i=0;i<int(a.size());i++){ for(int sum = S; sum >= 0; sum --){ dp[i][sum] = dp[i-1][sum]; if(sum >= a[i].second && dp[i-1][sum - a[i].second] + a[i].first > dp[i][sum]){ dp[i][sum] = dp[i-1][sum - a[i].second] + a[i].first; } } } // for(int i=0;i<n;i++){ // for(int j = 0; j<=S; j++){ // cout<<dp[i][j]<<" "; // }cout<<endl; // } cout<<dp[a.size() - 1][S]<<'\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...