using namespace std;
int knapsack(int* weights, int* values, int n, int maxWeight){↵
cin.tie(NULL), cout.tie(NULL);↵
↵
int dp[maxWeight + 1];↵
↵
memset(dp, 0, sizeof dp);↵
↵
int flag = 1;↵
↵
for(i = 1; i <= n; i++)↵
{↵
↵
for(j = maxWeight; j >= weights[i — 1]; j--)↵
↵
dp[j] = max(dp[j], values[i — 1] + dp[j — weights[i — 1]]);↵
↵
}↵
↵
int ans = dp[maxWeight];↵
↵
return ans;↵
}↵