given an integer array with all positive numbers and no duplicates find the number of possible combinations that add up to a positive integer target example nums 1 2 3 target 4 the possible combination ways are 1 1 1 1 1 1 2 1 2 1 1 3 2 1 1 2 2 3 1 note that different sequences are counted as different combinations therefore the output is 7 follow up what if negative numbers are allowed in the given array how does it change the problem what limitation we need to add to the question to allow negative numbers generates dp and finds result keyword arguments nums positive integer array without duplicates target integer describing what a valid combination should add to find number of possible combinations in nums that add up to target in topdown manner keyword arguments nums positive integer array without duplicates target integer describing what a valid combination should add to find number of possible combinations in nums that add up to target in bottomup manner keyword arguments nums positive integer array without duplicates target integer describing what a valid combination should add to generates dp and finds result keyword arguments nums positive integer array without duplicates target integer describing what a valid combination should add to find number of possible combinations in nums that add up to target in top down manner keyword arguments nums positive integer array without duplicates target integer describing what a valid combination should add to find number of possible combinations in nums that add up to target in bottom up manner keyword arguments nums positive integer array without duplicates target integer describing what a valid combination should add to
DP = None

def helper_topdown(nums, target):
    
    if DP[target] != -1:
        return DP[target]
    res = 0
    for num in nums:
        if target >= num:
            res += helper_topdown(nums, target - num)
    DP[target] = res
    return res


def combination_sum_topdown(nums, target):
    
    global DP
    DP = [-1] * (target + 1)
    DP[0] = 1
    return helper_topdown(nums, target)

def combination_sum_bottom_up(nums, target):
    
    combs = [0] * (target + 1)
    combs[0] = 1
    for i in range(0, len(combs)):
        for num in nums:
            if i - num >= 0:
                combs[i] += combs[i - num]
    return combs[target]