Combination

I want to write a program, which given two integer inputs j and k will output the combinations of j things partitions into k groups. For instance if j=5 and k=3 the output would be

(5, 0, 0)

(4, 1, 1)

(3, 2, 0)

(3, 1, 1)

(2, 2, 0)

I've got no idea what to do. I think I should use nested loop or use recursion. Please help.

[368 byte] By [vijaykcma] at [2007-9-28 13:04:38]
# 1
You can use recursion.suppose the method name is partition(j,k)then partition(j,k)=j,partition(0,k-1)j-1,partition(1,k-1) ....0,partition(j,k-1)
skyzha at 2007-7-12 8:52:33 > top of Java-index,Other Topics,Algorithms...
# 2
This should help, even without recursion: http://forum.java.sun.com/thread.jsp?forum=31&thread=239810 http://forum.java.sun.com/thread.jsp?forum=4&thread=225862
thpreussera at 2007-7-12 8:52:33 > top of Java-index,Other Topics,Algorithms...