제출 #701640

#제출 시각아이디문제언어결과실행 시간메모리
701640Mohamed_Kachef06Knapsack (NOI18_knapsack)C++17
0 / 100
109 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define int long long vector<int> v, w , k;; int dp[(int)1e5+2001][2001]; int knapsack(int i , int W){ if (i==0) return 0 ; if (~dp[i][W]) return dp[i][W]; int b =0 ; int a = knapsack(i-1 , W); if (W >= w[i]) b = knapsack(i-1 , W-w[i]) + v[i]; return dp[i][W] = max(a , b); } signed main(){ memset(dp , -1 , sizeof dp); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n , s ; cin >> s >> n ; v.resize(n+1) , w.resize(n+1) , k.resize(n+1); for (int i = 1 ; i<=n ; i++){ cin >> v[i] >> w[i] >> k[i]; k[i] = min(s/w[i] , k[i]); } for (int i = 1 ; i<=n ; i++){ for (int j = 1 ; j<k[i] ; j++){ w.push_back(w[i]); v.push_back(v[i]); } } n = v.size(); cout << knapsack(n , s); }
#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...