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. static ArrayList<Integer> list;
  11. static int target;
  12. static boolean bl;
  13. static boolean ex;
  14. static int rpl;
  15. public static void main (String[] args) throws java.lang.Exception
  16. {
  17.  
  18. Ideone nm = new Ideone();
  19. list = new ArrayList<Integer>();
  20. bl = false;
  21. ex = false;
  22. target = 24;
  23. nm.test(24);
  24.  
  25. }
  26.  
  27.  
  28. public void test(int k) {
  29.  
  30. for (int i = k; i>0; i--) {
  31. if(!ex) {
  32. if(sum(list) + i > target) {
  33. test(i-1);
  34. }
  35. else if(list.size() == 10) {
  36. /*
  37.   list.add(target - sum(list));
  38.   printFill(list); */
  39. int p = list.get(0);
  40. if(p*10>=target) {
  41. i = p;
  42. list.clear();
  43. }
  44.  
  45. } else {
  46. list.add(i);
  47. if(sum(list) == target) {
  48. printFill(list);
  49. if(bl)
  50. i = rpl;
  51. bl = false;
  52. } else {
  53. test(i);
  54. }
  55. }
  56. } else {
  57. System.out.print("t");
  58. }
  59. }
  60. }
  61.  
  62. public void printFill(ArrayList lt) {
  63. int i = 0;
  64. for ( i = 0; i< lt.size()-1; i ++) {
  65. System.out.print(lt.get(i)+",");
  66. }
  67. System.out.print(lt.get(i));
  68. System.out.println("");
  69.  
  70. i = list.get(list.size()-1);
  71. if(i > 1) {
  72. list.remove(list.size()-1);
  73. if(list.size()>0) {
  74. try {
  75. while (list.get(list.size()-1) == 1) {
  76. list.remove(list.size()-1);
  77. }
  78. } catch(Exception e ) { }
  79. /*if(list.size()==0) {
  80.   System.out.println("test");
  81.   ex = true;
  82.   }*/
  83. }
  84. } else if(i == 1 ) {
  85. try {
  86. while (list.get(list.size()-1) == 1) {
  87. list.remove(list.size()-1);
  88. }
  89. } catch(Exception e ) { }
  90. if(list.size()>0) {
  91. bl = true;
  92. rpl = list.remove(list.size()-1);
  93. } else {
  94. ex = true;
  95. }
  96. }
  97. }
  98.  
  99. public int sum(ArrayList<Integer> lt) {
  100. int k = 0;
  101. for ( int i = 0; i< lt.size(); i ++) {
  102. k = k + lt.get(i);
  103. }
  104.  
  105. return k;
  106. }
  107.  
  108. }
Success #stdin #stdout 0.52s 380544KB
stdin
Standard input is empty
stdout
24
23,1
22,2
22,1,1
21,3
21,2,1
21,1,1,1
20,4
20,3,1
20,2,2
20,2,1,1
20,1,1,1,1
19,5
19,4,1
19,3,2
19,3,1,1
19,2,2,1
19,2,1,1,1
19,1,1,1,1,1
18,6
18,5,1
18,4,2
18,4,1,1
18,3,3
18,3,2,1
18,3,1,1,1
18,2,2,2
18,2,2,1,1
18,2,1,1,1,1
18,1,1,1,1,1,1
17,7
17,6,1
17,5,2
17,5,1,1
17,4,3
17,4,2,1
17,4,1,1,1
17,3,3,1
17,3,2,2
17,3,2,1,1
17,3,1,1,1,1
17,2,2,2,1
17,2,2,1,1,1
17,2,1,1,1,1,1
17,1,1,1,1,1,1,1
16,8
16,7,1
16,6,2
16,6,1,1
16,5,3
16,5,2,1
16,5,1,1,1
16,4,4
16,4,3,1
16,4,2,2
16,4,2,1,1
16,4,1,1,1,1
16,3,3,2
16,3,3,1,1
16,3,2,2,1
16,3,2,1,1,1
16,3,1,1,1,1,1
16,2,2,2,2
16,2,2,2,1,1
16,2,2,1,1,1,1
16,2,1,1,1,1,1,1
16,1,1,1,1,1,1,1,1
15,9
15,8,1
15,7,2
15,7,1,1
15,6,3
15,6,2,1
15,6,1,1,1
15,5,4
15,5,3,1
15,5,2,2
15,5,2,1,1
15,5,1,1,1,1
15,4,4,1
15,4,3,2
15,4,3,1,1
15,4,2,2,1
15,4,2,1,1,1
15,4,1,1,1,1,1
15,3,3,3
15,3,3,2,1
15,3,3,1,1,1
15,3,2,2,2
15,3,2,2,1,1
15,3,2,1,1,1,1
15,3,1,1,1,1,1,1
15,2,2,2,2,1
15,2,2,2,1,1,1
15,2,2,1,1,1,1,1
15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