k Sum I&II
Givenn_distinct positive integers, integer_k(k<=n) and a numbertarget.
Find _k _numbers where sum is target. Calculate how many solutions there are?
Example
Given[1,2,3,4]
, k =2
, target =5
.
There are2
solutions:[1,4]
and[2,3]
.
Return2
.
分析:
动态规划。I求个数用动归,II求所有solution用搜索(DFS)。不懂为什么初始化是1
解法:
k Sum II
Find all possible k integers where their sum is target.
分析:
DFS
Last updated