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.  
  11. static int[] pai = new int[34];
  12. static int count = 0;
  13. // static HashSet<String> set = new HashSet<>();
  14.  
  15. public static void main (String[] args) throws java.lang.Exception
  16. {
  17. // your code goes here
  18. Arrays.fill(pai, 4);
  19. atama();
  20.  
  21. System.out.println(count);
  22. // System.out.println(set.size());
  23. }
  24.  
  25. static void atama() {
  26. for (int i = 0; i < 34; i++) {
  27. pai[i] -= 2;
  28. kotsu(4, 0);
  29. juntsu(4, 0);
  30. pai[i] += 2;
  31. }
  32. }
  33.  
  34. static void kotsu(int rem, int p) {
  35. if (rem == 0) {
  36. count++;
  37. // StringBuilder sb = new StringBuilder();
  38. // for (int i = 0; i < 34; i++) sb.append(pai[i]);
  39. // set.add(sb.toString());
  40. return;
  41. }
  42. for (int i = p; i < 34; i++) {
  43. if (pai[i] < 4) continue;
  44. pai[i] -= 3;
  45. kotsu(rem - 1, i);
  46. juntsu(rem - 1, 0);
  47. pai[i] += 3;
  48. }
  49. }
  50.  
  51. static void juntsu(int rem, int p) {
  52. if (rem == 0) {
  53. count++;
  54. // StringBuilder sb = new StringBuilder();
  55. // for (int i = 0; i < 34; i++) sb.append(pai[i]);
  56. // set.add(sb.toString());
  57. return;
  58. }
  59. for (int i = p; i < 27; i++) {
  60. if (i % 9 > 6) continue;
  61. if (pai[i] == 0) continue;
  62. if (pai[i+1] == 0) continue;
  63. if (pai[i+2] == 0) continue;
  64. pai[i]--;
  65. pai[i+1]--;
  66. pai[i+2]--;
  67. juntsu(rem - 1, i);
  68. pai[i]++;
  69. pai[i+1]++;
  70. pai[i+2]++;
  71. }
  72. }
  73. }
Success #stdin #stdout 0.16s 54076KB
stdin
Standard input is empty
stdout
12971847