제출 #1018248

#제출 시각아이디문제언어결과실행 시간메모리
1018248arkash707Knapsack (NOI18_knapsack)C++17
37 / 100
1039 ms31896 KiB
#include<iostream> #include<string> #include<algorithm> #include<unordered_set> #include<unordered_map> #include<vector> #define ll long long using namespace std; int mod = 1000000007; int s, n; vector<ll> c(2001, 0); vector<ll> w(2001, 0); vector<ll> q(2001, 0); vector<vector<ll>> dp(2001, vector<ll>(2001, -1)); long long solve() { ll ans = 0; dp[0][0] = 0; for (int i=1; i<=n; i++) { for (int j=0; j<=s; j++) { //buy from 0 to q[i] of good i for (int k=0; k<=q[i]; k++) { if (j-k*w[i] < 0 || dp[i-1][j-k*w[i]] == -1) continue; dp[i][j] = max(dp[i][j], dp[i-1][j-k*w[i]] + c[i] * k); } ans = max(ans, dp[i][j]); } } return ans; } int main() { cin >> s >> n; for (int i=1; i<=n; i++) cin >> c[i] >> w[i] >> q[i]; cout << solve() << "\n"; }
#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...