fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4.  
  5. /* Name of the class has to be "Main" only if the class is public. */
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. int n = 5;
  11. for (int i = 0; i < 20; i++){
  12. System.out.println(new Ideone().a(n));
  13. }
  14. }
  15.  
  16. Map a=new HashMap();List a(int b){List c=new ArrayList();int d=b,e=b(b,d),f=(int)(Math.random()*e),g,i;while(b>0){for(g=0;g++<Math.min(d, b);f-=i){i=b(b-g,g);if(f<i)break;}c.add(g);d=g;b-=g;}return c;}int b(int b,int c){if(b<1)return 1;List d=Arrays.asList(b,c);if(a.containsKey(d))return(int)a.get(d);int e,f;for(e=f=0;f++<Math.min(c, b);)e+=b(b-f,f);a.put(d,e);return e;}
  17. }
Success #stdin #stdout 0.1s 320256KB
stdin
Standard input is empty
stdout
[4, 1]
[2, 1, 1, 1]
[1, 1, 1, 1, 1]
[1, 1, 1, 1, 1]
[4, 1]
[1, 1, 1, 1, 1]
[3, 2]
[5]
[3, 1, 1]
[2, 1, 1, 1]
[3, 1, 1]
[1, 1, 1, 1, 1]
[4, 1]
[5]
[1, 1, 1, 1, 1]
[4, 1]
[3, 2]
[2, 2, 1]
[3, 2]
[4, 1]