Question: Python pls def NWSD(n : int, s : {int}) -> int: pass The NWSD function takes two arguments: the first in an int (name it

 Python pls def NWSD(n : int, s : {int}) -> int:

pass The NWSD function takes two arguments: the first in an int

Python pls

def NWSD(n : int, s : {int}) -> int: pass

The NWSD function takes two arguments: the first in an int (name it n) and the second is a set of positive ints (so, it cannot contain 0; name it s). NWDS returns an int computing the Number of Ways to Sum to n all the values in the set s when allowing Duplicates. For example, calling NWSD(5,{1,2,3,4,5)) returns 7, because there are 7 different ways for the value's in {1,2,3,4,5} to sum to 5. You do not have to compute how these values sum to 5; just compute how many sum to 5. 1. as 5 2. as 4+1 3. as 3+2 4. as 3+1+1 5. as 2+2+1 6. as 2+1+1+1 7. as 1+1+1+1+1 The second arugment can be any arbirary set; so, another example is calling NSWD(7,{2,3,5}) which returns 2: 1. as 5+2, 2. as 3+2+2 You must write the NWSD function recursively. For small arguments, such an NWSD can compute its result in under a few seconds. In addition, you may use all of Python's other programming features including rebinding and mutation) Think carefully about how to write this recursive function. Given the specification of the function (including its arguments, result, and their types), think carefully about how to write the base case(s) and how to break down the problem into similar/strictly smaller subproblems and successfully combine the solutions of these recursively solved subproblems. "Its elephants all the way down." Hint 0: It is useful to think concretely about some specific set s. I suggest something small but not too small (not a base case): think about its smaller subproblems and their solutions (which you should be able to compute by hand). Hint 1: Given n and s, for what cases can you trivially know the solution without recurring? Recognize and return the correct value for those cases: some might be more general/complicated than you think; you'll undestand more as you investigate solving the problem recursively. Hint 2: For any value in s, count the number of solutions (a) using that value and (b) not using the value. Do not mutate any parameters: if you need a mutation of a parameter, make a local copy of its information and then mutate the copy. Do not import/use any other functions from any other modules. Memoize cannot decorate NWSD: We cannot use Memoize to speed up NWSD because it's set parameter is mutable (not hashable) and therefore cannot be used as a key in Memoize's dict/cache of arguments. If we change its second argument to be a frozenset and we could use Memoize: the changed function would be very similar, but a bit harder to write, so we will stick with using set parameter

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!