Skip to content

Practice Find Sum of Array Product of Magical Sequences

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#3539
LeetCode Problem

Find Sum of Array Product of Magical Sequences

Problem Statement

Consider all ordered sequences seq of length m with indices from 0 through nums.length - 1; repeated indices are allowed. A sequence is magical when the sum of 2^seq[i] over its entries has exactly k set bits in binary. Its contribution is the product of nums[seq[i]] over all entries. Return the sum of contributions of all magical sequences modulo 10^9 + 7.

Source: Find Sum of Array Product of Magical Sequences on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
m = 5, k = 5, nums = [1,10,100,10000,1000000]
Output
991600007

# Example 2

Input
m = 2, k = 2, nums = [5,4,3,2,1]
Output
170

# Example 3

Input
m = 1, k = 1, nums = [28]
Output
28

Constraints

1 <= k <= m <= 30
1 <= nums.length <= 50
1 <= nums[i] <= 10^8

Related LeetCode Problems

Practice more problems similar to Find Sum of Array Product of Magical Sequences.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.