MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / ks

Function ks

Dynamic Programming/0-1Knapsack.cpp:10–20  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8// Space: O(n)
9#include<bits/stdc++.h>
10int ks(vector<int> &val, vector<int> &wt, int ind, int W){
11 if(ind==0) {
12 if(wt[0]<=W) return val[0];
13 return 0;
14 }
15 int nt=ks(val,wt,ind-1,W);
16 int t=INT_MIN;
17 if(wt[ind]<=W)
18 t=val[ind]+ks(val,wt,ind-1,W-wt[ind]);
19 return max(t,nt);
20}
21
22int maxProfit(vector<int> &val, vector<int> &wt, int n, int W)
23{

Callers 1

maxProfitFunction · 0.85

Calls 1

maxFunction · 0.50

Tested by

no test coverage detected