Submission #471118

#TimeUsernameProblemLanguageResultExecution timeMemory
471118avijeet_03Knapsack (NOI18_knapsack)C++17
49 / 100
1092 ms2048 KiB
#include "bits/stdc++.h" using namespace std; #define int long long const int mod = 1e9 + 7; const int N = 105; int value[N], weight[N], amount[N]; int dp[N][2005]; int calc(int i, int cap) { if (i == 0 or cap == 0) return 0; int &res = dp[i][cap]; if (res != -1) return res; int temp = 0; for (int k = 0; k <= amount[i]; k++) if (k * weight[i] <= cap) temp = max(temp, k * value[i] + calc(i - 1, cap - k * weight[i])); return res = temp; } void test_case() { int cap, n; cin >> cap >> n; for (int i = 1; i <= n; i++) cin >> value[i] >> weight[i] >> amount[i]; memset(dp, -1, sizeof(dp)); int res = calc(n, cap); cout << res << "\n"; } signed main() { ios::sync_with_stdio(0); cin.tie(0); test_case(); 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...