I'm looking for all the possible combination of number and the permutation of them in a fixed size of array. For example, I have the total number of 5 the desired output will be
5 0 0 0
0 5 0 0
0 0 5 0
0 0 0 5
4 1 0 0
1 4 0 0
1 0 4 0
1 0 0 4
0 1 4 0
and so on... is this possible ?
6 -1 0 0?2 2 1 0, be acounted too?dp[i][j] = number of ways to sum to j using i numbers. If you want to print all the combinations, use a recursive DFS as shown in pfctgeorge's answer.