Submission #475628

#TimeUsernameProblemLanguageResultExecution timeMemory
475628vishnu_sujithKnapsack (NOI18_knapsack)C++17
0 / 100
109 ms262148 KiB
#include <bits/stdc++.h> using namespace std; #ifdef DEBUG #define LOG(...) cerr << "[" << #__VA_ARGS__ << "]: " << repr(__VA_ARGS__) << endl; #define MSG(args) cerr << args << "\n"; #define debug(x) x #else #define LOG(...) #define MSG(args) #define debug(x) #endif #define mp make_pair #define pb push_back #define sz(x) (int((x).size())) #define ms(x, v) memset((x), v, sizeof(x)) #define all(x) (x).begin(), (x).end() #define endl '\n' using ll = long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vii = vector<pii>; using vvi = vector<vi>; const int mxN = int(1e5) + 10; int n, S; int v[mxN], w[mxN], k[mxN], memo[mxN][2005]; int solve(int i, int s) { if (i >= n || s <= 0) return 0LL; else if (memo[i][s] != -1) return memo[i][s]; int res = 0; for (int j = 0; j <= k[i]; ++j) { if (s - (1LL * j * w[i]) >= 0) res = max(res, solve(i + 1, s - (1LL * j * w[i])) + v[i] * j); else break; } return memo[i][s] = res; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); ms(memo, 0xff); cin >> S >> n; for (int i = 0; i < n; ++i) cin >> v[i] >> w[i] >> k[i]; cout << solve(0, 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...