제출 #440995

#제출 시각아이디문제언어결과실행 시간메모리
440995asdf1234codingKnapsack (NOI18_knapsack)C++14
73 / 100
246 ms262148 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; #define ll long long #define MOD (ll) (1e9+7) int main() { ios_base::sync_with_stdio(false); ll s,n; cin>>s>>n; vector<ll> v; // cost vector<ll> w; // weight vector<ll> k; // copies ll maxW = 0; for(int i=0; i<n; i++) { int a,b,c; cin>>a>>b>>c; v.push_back(a); w.push_back(b); k.push_back(c); maxW += w[i]*k[i]; } vector<vector<ll> > dp(n+2, vector<ll> (s+1)); dp[0][0] = 0; for(int i=1; i<=n; i++) { for(int j=0; j<=s; j++) { for(int m=0; m<=k[i-1]; m++) { if(j>=(m*w[i-1])) { // if our current weight is greater than the weight of m copies of i dp[i][j] = max(dp[i][j], dp[i-1][j-(m*w[i-1])] + m*v[i-1]); //cout<<dp[i][j]<<'\t'<<i<<'\t'<<j<<'\t'<<endl; } else { break; } } } } cout<<dp[n][s]<<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...