제출 #965439

#제출 시각아이디문제언어결과실행 시간메모리
965439vjudge1Knapsack (NOI18_knapsack)C++17
73 / 100
1087 ms8820 KiB
#include<bits/stdc++.h> #define int long long using namespace std; int n,s,V[1000001], W[1000001], K[1000001], dp[2][2010]; signed main(){ cin.tie(nullptr)->sync_with_stdio(false); cin >> s >> n; for(int i = 1; i<=n; ++i) cin >> V[i] >> W[i] >> K[i]; for(int i = 1; i<=n; ++i){ int cur = i&1, pre = cur^1; for(int j = 0; j<=s; ++j){ dp[cur][j] = dp[pre][j]; for(int k = 1; k<=K[i]; ++k){ if(j - W[i]*k < 0) break; dp[cur][j] = max(dp[cur][j], dp[pre][j - W[i]*k] + V[i]*k); } } } cout << dp[n&1][s]; }
#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...