fork(1) download
  1. import java.util.Arrays;
  2.  
  3. public class Main
  4. {
  5. static int[] array;
  6. static void fillRow(int N, int pos)
  7. {
  8. if (pos == 0)
  9. // (N+1)*(N+2)*(N+3)/6 is a lot
  10. array = new int[2*N];
  11. if (pos == array.length-1)
  12. {
  13. // we don't really have a choice of value here since we need to get to N
  14. array[array.length-1] = N;
  15. System.out.println(Arrays.toString(array));
  16. return;
  17. }
  18. for (int i = N; i >= 0; i--)
  19. {
  20. array[pos] = i;
  21. fillRow(N-i, pos+1);
  22. }
  23. }
  24.  
  25. public static void main(String[] args)
  26. {
  27. fillRow(2, 0);
  28. }
  29. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
[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]