제출 #961909

#제출 시각아이디문제언어결과실행 시간메모리
961909Bee_RKnapsack (NOI18_knapsack)C++17
73 / 100
101 ms262144 KiB
#include <bits/stdc++.h> #define int long long #define f cin #define g cout using namespace std; /*ifstream f("knap.in"); ofstream g("knap.out");*/ vector<vector<int>> used; vector<int> dp, weight, value; int s, n, result; int32_t main(){ f>>s>>n; used.resize(s+1,vector<int>(n+1,0)); weight.resize(n+1); value.resize(n+1); for(int i=1;i<=n;i++){ f>>value[i]>>weight[i]>>used[0][i]; } dp.resize(s+1,0); for(int i=1;i<=s;i++){ int mx=0, mxv=0; for(int j=1;j<=n;j++){ int k=i-weight[j]; if(k>=0 && dp[k]+value[j]>mxv && used[k][j]>0){ mx=j; mxv=dp[k]+value[j]; } } int k=i-weight[mx]; for(int j=1;j<=n;j++) if(j==mx) used[i][j]=used[k][j]-1; else used[i][j]=used[k][j]; dp[i]=mxv; if(mxv>result) result=mxv; } g<<result<<'\n'; return 0; }
#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...