제출 #772280

#제출 시각아이디문제언어결과실행 시간메모리
772280RandomChickenKnapsack (NOI18_knapsack)C++11
12 / 100
1 ms212 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using vll = vector<ll>; #define f0r(i,n) for(ll i = 0; i<(ll)(n); i++) int main(){ ll capacity,n; cin>>capacity>>n; ll value[n], weight[n], quantity[n]; f0r(i,n) cin>>value[i]>>weight[i]>>quantity[i]; ll dp[capacity+1]; // in theory: dp[n+1][capacity+1]; but made 1D for memory saving f0r(j,capacity+1) dp[j] = 0; // initial row with nothing considered ll dpMax = 0; f0r(i,n){ // considering item i ll boughtCount[capacity+1]; for(ll j = capacity; j>=0; j--){ boughtCount[j] = 0; if(j+1<=capacity){ if(dp[j+1]>dp[j]){ dp[j] = dp[j+1]; boughtCount[j] = boughtCount[j+1]; } } if(j+weight[i]<=capacity){ if(boughtCount[j+weight[i]]+1<=quantity[i] && dp[j+weight[i]]+value[i]>dp[j]){ dp[j] = dp[j+weight[i]]+value[i]; boughtCount[j] = boughtCount[j+weight[i]]+1; } } } f0r(j,capacity+1){ dpMax = max(dpMax,dp[j]); // cout<<setw(5)<<dp[j]; } // cout<<"\n"; } cout<<dpMax; }
#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...