Input: nums =[1,2,3], k =3Output: 6Explanation:
There are `5` subsequences of nums with non-zero power:* The subsequence `[_**1**_ ,_**2**_ ,_**3**_]` has `2` subsequences with`sum == 3`:`[1,2,_3_]` and `[_1_ ,_2_ ,3]`.* The subsequence `[_**1**_ ,2,_**3**_]` has `1` subsequence with`sum == 3`:`[1,2,_3_]`.* The subsequence `[1,_**2**_ ,_**3**_]` has `1` subsequence with`sum == 3`:`[1,2,_3_]`.* The subsequence `[_**1**_ ,_**2**_ ,3]` has `1` subsequence with`sum == 3`:`[_1_ ,_2_ ,3]`.* The subsequence `[1,2,_**3**_]` has `1` subsequence with`sum == 3`:`[1,2,_3_]`.Hence the answer is`2 + 1 + 1 + 1 + 1 = 6`.
Input: nums =[2,3,3], k =5Output: 4Explanation:
There are `3` subsequences of nums with non-zero power:* The subsequence `[_**2**_ ,_**3**_ ,_**3**_]` has 2 subsequences with`sum == 5`:`[_2_ ,3,_3_]` and `[_2_ ,_3_ ,3]`.* The subsequence `[_**2**_ ,3,_**3**_]` has 1 subsequence with`sum == 5`:`[_2_ ,3,_3_]`.* The subsequence `[_**2**_ ,_**3**_ ,3]` has 1 subsequence with`sum == 5`:`[_2_ ,_3_ ,3]`.Hence the answer is`2 + 1 + 1 = 4`.
For each subsequence, its power is the number of subsequences whose sum is exactly k. The sum of the power of all subsequences is the total number of ways to pick any subset whose sum is k, for all possible subsets. This is a classic subset sum problem, and we can use dynamic programming to count the number of ways to reach each sum.