|
-
December 4th, 2008, 05:20 PM
#1
URGENT: I need a pseudo code for performing a certain task
Dear Members,
If you can help me, I will be greatly thankful,
I want to write an algorithm to do the following:
Input: two positive integers N,K
The output should be an array whose number of columns is N,
and its rows lists all the possible combinations of natural integers less than or equal K (possibly zero) such that the sum of every row is K.
To clerify more, Let N=3, K=2
the output array is
2 0 0
1 1 0
1 0 1
0 2 0
0 0 2
0 1 1
Notice that the sum of every row = K=2
Another example, N=4,K=3
3 0 0 0
2 1 0 0
2 0 1 0
2 0 0 1
1 2 0 0
1 1 1 0
1 1 0 1
1 0 2 0
1 0 1 1
1 0 0 2
0 3 0 0
0 2 1 0
0 2 0 1
0 1 2 0
0 1 1 1
0 1 0 2
0 0 3 0
0 0 2 1
0 0 1 2
0 0 0 3
Thanks,
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|