제출 #1118076

#제출 시각아이디문제언어결과실행 시간메모리
1118076vjudge1Knapsack (NOI18_knapsack)C++14
49 / 100
4 ms512 KiB
#include <bits/stdc++.h> #define sts(v) stable_sort(v.BE, v.E) #define Rsts(v) stable_sort(v.rBE, v.rE) #define rev(v) reverse(v.BE, v.E) #define BE begin() #define rBE rbegin() #define E end() #define rE rend() #define pb push_back #define ppb pop_back() #define pf push_front #define ppf pop_front() #define F first #define S second using namespace std; using ll = long long; struct datos{ int val, w, k; }; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int W, n; cin >> W >> n; vector<datos> v(n + 1); for(int i = 1; i <= n; i++){ int val, w, k; cin >> val >> w >> k; v[i] = {val, w, k}; } if(n == 1){ ll sum = 0; int mini = min(v[1].k, W / v[1].w); while(mini--) sum += v[1].val; cout << sum; return 0; } vector<ll> ans(W + 1); for(int i = 1; i <= n; i++) for(int w = W; w >= 0; w--) for(int k = 1; k <= min(10, v[i].k); k++){ int x = w + v[i].w * k; if(x <= W) ans[x] = max(ans[x], ans[w] + v[i].val * k); } ll res = 0; for(int i = 0; i <= W; i++) res = max(res, ans[i]); cout << res; 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...