fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. System.out.println(print(4));
  13. }
  14.  
  15. static List<List<Integer>> print(int num) {
  16. List<Integer> list = new LinkedList<>();
  17. list.add(num);
  18. List<List<Integer>> ret = new LinkedList<>();
  19. ret.add(list);
  20. if(num == 1) return ret;
  21. for(int i=1;i<(num+1)/2;i++) {
  22. for(List<Integer> l1 : print(i)) {
  23. for(List<Integer> l2: print(num-i)) {
  24. List<Integer> ans = new LinkedList<>(l1);
  25. ans.addAll(l2);
  26. ret.add(ans);
  27. }
  28. }
  29. }
  30.  
  31. return ret;
  32. }
  33. }
Success #stdin #stdout 0.11s 320576KB
stdin
Standard input is empty
stdout
[[4], [1, 3], [1, 1, 2]]