K-Sum

Given n _distinct positive integers, integer _k(k<=n) and a number target.

Find _k _numbers where sum is target. Calculate how many solutions there are?

Example

Example 1

Input:
List = [1,2,3,4]
k = 2
target = 5
Output: 2
Explanation: 1 + 4 = 2 + 3 = 5

Example 2

Input:
List = [1,2,3,4,5]
k = 3
target = 6
Output: 1
Explanation: There is only one method. 1 + 2 + 3 = 6

Note

用dp[i][j][k]表示前i个数里选j个和为k的方案数

Code

Last updated