제출 #635837

#제출 시각아이디문제언어결과실행 시간메모리
635837zeroesandonesKnapsack (NOI18_knapsack)C++17
100 / 100
225 ms3608 KiB
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef long double ld; typedef vector<ll> vi; typedef pair<ll, ll> pi; #define FOR(i, j, k) for (ll i = j; i < (ll) k; ++i) #define FORD(i, j, k) for (ll i = j; i >= (ll) k; --i) #define nl "\n" #define all(x) (x).begin(), (x).end() #define sc second #define fr first #define pb push_back void solve() { int s, n; cin >> s >> n; int v[n], w[n], k[n]; FOR(i, 0, n) { cin >> v[i] >> w[i] >> k[i]; k[i] = min(k[i], s/w[i]); } ll dp[s + 1] = {}; FOR(i, 0, n) { bool improv = true; FOR(j, 0, k[i]) { if(!improv) continue; improv = false; FORD(p, s, 0) { if(p - w[i] >= 0) { if(dp[p - w[i]] + v[i] > dp[p]) { dp[p] = dp[p - w[i]] + v[i]; improv = true; } } } } } cout << dp[s] << nl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll t = 1; // cin >> t; while (t--) { solve(); } }
#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...