제출 #919247

#제출 시각아이디문제언어결과실행 시간메모리
919247AndrijaMKnapsack (NOI18_knapsack)C++14
0 / 100
51 ms262144 KiB
#include <bits/stdc++.h> using namespace std; long long s,n; vector<pair<long long,pair<long long,long long>>>x; long long dp[100005][2005]; long long f(long long idx,long long sum) { if(idx==n) { return 0; } if(dp[idx][sum]!=-1) { return dp[idx][sum]; } long long rez=0; rez=max(rez, f(idx+1,sum)); for(long long i=1;i<=min(s,x[idx].second.second);i++) { if(i*x[idx].second.first+sum>s) { break; } rez=max(rez, f(idx+1,i*x[idx].second.first+sum)+x[idx].first*i); } return dp[idx][sum]=rez; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin>>s>>n; memset(dp,-1,sizeof dp); for(long long i=0;i<n;i++) { long long v,w,k; cin>>v>>w>>k; x.push_back({v,{w,k}}); } cout<<f(0,0)<<endl; }
#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...