제출 #1279307

#제출 시각아이디문제언어결과실행 시간메모리
1279307efegKnapsack (NOI18_knapsack)C++20
73 / 100
1095 ms2860 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back typedef vector<int> vi; int n,S; vi val,we,have; int32_t main(){ ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr); cin >> S >> n; for (int i = 0; i < n; i++){ int v,w,k; cin >> v >> w >> k; val.pb(v); we.pb(w); have.pb(k); } vi dp(S + 10,0); for (int i = 0; i < n; i++){ vi ndp(S + 10,0); for (int j = 0; j <= S; j++){ if (j != 0) ndp[j] = dp[j]; if (j != 0) ndp[j] = max(ndp[j],ndp[j-1]); for (int k = 1; k <= have[i]; k++){ int w = k * we[i], v = k * val[i]; if (j - w < 0) break; ndp[j] = max(ndp[j],dp[j - w] + v); } //cout << i << " " << j << ": " << dp[i][j] << endl; } dp = ndp; } cout << dp[S] << endl; 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...