Perfect Sum Problem

Given an array of non-negative integers and a target sum, return the number of subsets with that sum modulo 1e9+7. This is the standard GFG-style subset-sum counting problem and is ideal for understanding DP table transitions.

Input Format

nums = array of non-negative integers, target = desired sum

Output Format

count of subsets with sum target modulo 1e9+7

Constraints

  • 1 <= nums.length <= 100; 0 <= nums[i] <= 1000; 0 <= target <= 1000

Examples

Example 1:

Input:

nums = [2,3,5,6,8,10]
target = 10

Output:

3

Explanation:

The valid subsets include [10], [2,8], and [2,3,5].

Example 2:

Input:

nums = [0,0,1]
target = 1

Output:

4

Explanation:

Each zero doubles the count of the valid subset [1].

Loading...
Perfect Sum Problem - Dp Knapsack DSA Problem