Submission #1079033

#TimeUsernameProblemLanguageResultExecution timeMemory
1079033Albara_AbdulhafithKnapsack (NOI18_knapsack)C++17
0 / 100
106 ms129304 KiB
#include <bits/stdc++.h> using namespace std; #define fastIO ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr) #define all(x) x.begin(),x.end() #define take(x) for(int &el : x){ cin >> el;} typedef vector<int> vi; typedef vector<vi> vvi; typedef long long ll; const int MAX_N = 105; const int MAX_K = 15; const int MAX_S = 2005; int n, S, k, tot_size; ll v, w; ll memo[MAX_N * MAX_K][MAX_S]; vector<ll> V, W; ll dp(int id, ll remW) { if(remW == 0 || id == tot_size || W[id] > remW){return 0;} if(memo[id][remW] != -1){return memo[id][remW];} return memo[id][remW] = max(V[id] + dp(id + 1, remW - W[id]), dp(id + 1, remW)); } void solve(){ scanf("%d %d", &S, &n); memset(memo, -1, sizeof memo); V.clear(); W.clear(); for(int i = 0; i < n; i++) { scanf("%lld %lld %d", &v, &w, &k); for(int j = 0; j < k; j++) { V.push_back(v); W.push_back(w); } } tot_size = (int)V.size(); ll ans = dp(0, S); printf("%lld\n", ans); } int main(){ fastIO; int tc = 1; // scanf("%d", &tc); while (tc--) { solve(); } return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'void solve()':
knapsack.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     scanf("%d %d", &S, &n);
      |     ~~~~~^~~~~~~~~~~~~~~~~
knapsack.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         scanf("%lld %lld %d", &v, &w, &k);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...