• top down of 0-1 knpsk

    From Kunal Goswami@21:1/5 to All on Thu Mar 9 04:29:43 2023
    Hello guys,
    Can someone plz do some modification of my code. It is code for implementing 0-1 knapsack. It has run using dynmaic programming and bottoom up means double loop

    class Solution:

    #Function to return max value that can be put in knapsack of capacity W.
    def knapSack(self,W, wt, val, n):

    dp = [0 for i in range(W+1)]

    for i in range(1, n+1):
    for w in range(W, 0, -1):
    if wt[i-1] <= w:
    dp[w] = max(dp[w], dp[w-wt[i-1]]+val[i-1])

    return dp[W]

    It will run in following link https://practice.geeksforgeeks.org/problems/0-1-knapsack-problem0945/1

    I want to run it using recursion means same logic as above but not using loop but using recursion.

    --
    *Disclaimer: *This email and any files transmitted with it are confidential
    and intended solely for the use of the individual or entity to whom they
    are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is
    intended only for the individual named. If you are not the named addressee
    you should not disseminate, distribute or copy this e-mail. Please notify
    the sender immediately by e-mail if you have received this e-mail by
    mistake and delete this e-mail from your system. If you are not the
    intended recipient you are notified that disclosing, copying, distributing
    or taking any action in reliance on the contents of this information is strictly prohibited.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)