제출 #595347

#제출 시각아이디문제언어결과실행 시간메모리
595347yaroslav06Knapsack (NOI18_knapsack)C++14
73 / 100
1051 ms2124 KiB
#include <iostream> const int N = 2001, M = 1e5; using namespace std; typedef long long ll; int s, n, v[M], w[M], k[M]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int dp[N][2]{}; cin >> s >> n; for(int i = 0; i < n; ++i) cin >> v[i] >> w[i] >> k[i]; for(int i = 0; i < n; ++i){ for(int j = 1; j <= k[i] && j * w[i] <= s; ++j) for(int t = s; t - j * w[i] >= 0; --t) dp[t][1] = max(dp[t][1], dp[t - j * w[i]][0] + j * v[i]); for(int j = 0; j <= s; ++j) dp[j][0] = dp[j][1]; } cout << dp[s][0] << '\n'; }
#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...