Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // https://oj.uz/problem/view/NOI18_knapsack 73 puncte
- #include <iostream>
- using namespace std;
- int dp[101][2001], v[2001], w[2001], k[2001];
- int main()
- {
- int S, N;
- cin >> S >> N;
- for(int i = 1;i<=N;i++)
- cin >> v[i] >> w[i] >> k[i];
- for(int i = 0;i<=N;i++)
- {
- for(int j = 0;j<=S;j++)
- {
- if(i == 0 || j == 0) dp[i][j] = 0;
- else
- {
- dp[i][j] = dp[i-1][j];
- for(int nr = 1; nr * w[i] <= j && nr <= k[i];nr++)
- {
- dp[i][j] = max(dp[i][j], dp[i - 1][j - nr * w[i]] + v[i] * nr);
- }
- }
- }
- }
- cout << dp[N][S];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement