Problem 950
Combination Sum IV
Medium · 20 pts · Array, Dynamic Programming
Problem
Given distinct positive integers and a TARGET, count the ordered sequences of numbers from the array (each number may be used any number of times) that add up to TARGET. Different orders count as different sequences, so 1 2 and 2 1 are counted separately. Print the count modulo 1000000007. Let ways[t] be the count for sum t: ways[t] is the sum of ways[t - x] over every number x not larger than t, with ways[0] = 1. Keep the counts in a 64-bit integer type (long long in C++, long in Java) and take the remainder after every addition and multiplication: adding or multiplying two remainders can be larger than a 32-bit int can hold (Python needs nothing special).
Input
The first line contains N and TARGET. The second line contains the N distinct numbers.
Output
Print the number of ordered sequences modulo 1000000007.
Constraints
1 <= N <= 200; 1 <= numbers <= 1000; 1 <= TARGET <= 1000
Example input
3 4 1 2 3
Example output
7
Explanation
With 1 2 3 and TARGET = 4, the sequences are 1111, 112, 121, 211, 22, 13 and 31, so the answer is 7.