Given a number N and an array ? How to distribute N among the array as the following example:
N = 5 and array of size 4;
[5,0,0,0]
[0,5,0,0]
[0,0,5,0]
[0,0,0,5]
[4,1,0,0]
[4,0,1,0]
[4,0,0,1]
[1,4,0,0]
[0,4,1,0]
[0,4,0,1]
[1,0,4,0]
[0,1,4,0]
[0,0,4,1]
.
..
..
[2,1,2,0]
..
..
...
and so on
The important thing is that the sum of whole array is N!
I want to implement a hill climbing algorithm so I want to generate all successors, then hill climbing can choose from the list.