제출 #1079181

#제출 시각아이디문제언어결과실행 시간메모리
1079181Albara_AbdulhafithKnapsack (NOI18_knapsack)C++17
37 / 100
107 ms111004 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 = 100; const int MAX_K = 10; const int MAX_S = 2005; int n, k, tot_size; ll v, w, S; ll memo[MAX_N * MAX_K + 5][MAX_S]; vector<ll> V, W; ll dp(int id, ll remW) { if(remW == 0 || id == tot_size ){return 0;} if(memo[id][remW] != -1){return memo[id][remW];} if(W[id] > remW){return dp(id + 1, remW);} return memo[id][remW] = max(V[id] + dp(id + 1, remW - W[id]), dp(id + 1, remW)); } void solve(){ cin >> S >> n; memset(memo, -1, sizeof memo); V.clear(); W.clear(); for(int i = 0; i < n; i++) { cin >> 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", ans); } int main(){ fastIO; int tc = 1; // scanf("%d", &tc); while (tc--) { solve(); } 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...