You have unread notifications. Click here.

Knapsack Recursion

Loading ...
Start Coding
using namespace std;
vector<int> w={5,5,4,7,6};
vector<int> p={4,4,3,7,3};
int maxW=10,n=5;
int solve(int i, int weight){
--return 0;
-int a = 0, b=0;
-if(w[i]+weight <= maxW)
--a = p[i] + solve(i+1, weight+w[i]);
-b = solve(i+1, weight);
-return a > b ? a : b;
int main(){
-cout<< solve(0,0) <<endl;


English Version


Answer the following questions according to what you learned from the video.
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Comments & Feedback

ملحوظة يتم مراجعة التعليقات قبل ظهورها من قبل الإدارة. رجاء عدم كتابة نفس التعليق أكثر من مرة.
Back to Course