Find the Sum of the Power of All Subsequences

You are given an integer array nums of length n and a positive integer k.

The power of an array of integers is defined as the number of subsequences with their sum equal to k.

Return the sum of power of all subsequences of nums.

Since the answer may be very large, return it modulo 10^9 + 7.

Example 1
Inputnums = [1,2,3], k = 3
Output6
There are five subsequences of nums with non-zero power, and their powers sum to 2 + 1 + 1 + 1 + 1 = 6.
Example 2
Inputnums = [2,3,3], k = 5
Output4
There are three subsequences of nums with non-zero power, and their powers sum to 2 + 1 + 1 = 4.

Constraints

  • 1 <= n <= 100
  • 1 <= nums[i] <= 10^4
  • 1 <= k <= 100

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate