import java.util.Arrays; public class Main { static int[] array; static void fillRow(int N, int pos) { if (pos == 0) // (N+1)*(N+2)*(N+3)/6 is a lot array = new int[2*N]; if (pos == array.length-1) { // we don't really have a choice of value here since we need to get to N array[array.length-1] = N; return; } for (int i = N; i >= 0; i--) { array[pos] = i; fillRow(N-i, pos+1); } } { fillRow(2, 0); } }
Standard input is empty
[2, 0, 0, 0] [1, 1, 0, 0] [1, 0, 1, 0] [1, 0, 0, 1] [0, 2, 0, 0] [0, 1, 1, 0] [0, 1, 0, 1] [0, 0, 2, 0] [0, 0, 1, 1] [0, 0, 0, 2]