Professional Documents
Culture Documents
20BCS3793 - Tushar 7
20BCS3793 - Tushar 7
CODE:
#include<iostream>
#include<vector>
usingnamespacestd;
intmax(inta, intb)
{
return (a>b) ? a : b;
}
intknapsack(intC, vector<int>weight, vector<int>value, intn)
{
inti, w;
vector<vector<int>>K(n + 1, vector<int>(C + 1));
intmain()
{
vector<int>val, wt;
intn = 0, W = 0, x = 0;
cout<<"Enter no of Values"<<endl;
cin>>n;
cout<<"Enter Values"<<endl;
for (inti = 0; i<n; i++)
{
cin>>x;
val.push_back(x);
}
cout<<"Enter weights corresponding to the values"<<endl;
for (inti = 0; i<n; i++)
{
cin>>x;
wt.push_back(x);
}
return0;
}
OUTPUT
TIME COMPLEXITY
O(N*W)