Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. using namespace std;
  4.  
  5. const int MAX = 60;
  6.  
  7. int n, t, o_inx, result, order[50000][10], number[MAX][10], p_order[10];
  8. bool checkNumber[10];
  9.  
  10. void getMax(int x) {
  11. int out = 0, inx = 1, r = 1, score = 0;
  12. bool checkBase[5];
  13.  
  14. while(r <= n) {
  15. while(out < 3) {
  16. if(number[r][order[x][inx]] == 0) {
  17. out++;
  18. inx++;
  19. }
  20. else if(number[r][order[x][inx]] == 1) {
  21. for(int i=3;i>=1;i--) {
  22. if(checkBase[i]) {
  23. if(i == 3) {
  24. score++;
  25. checkBase[i] = false;
  26. }
  27. else {
  28. checkBase[i+1] = true;
  29. checkBase[i] = false;
  30. }
  31. }
  32. }
  33. checkBase[1] = true;
  34. inx++;
  35. }
  36. else if(number[r][order[x][inx]] == 2) {
  37. for(int i=3;i>=1;i--) {
  38. if(checkBase[i]) {
  39. if(i >= 2) {
  40. score++;
  41. checkBase[i] = false;
  42. }
  43. else {
  44. checkBase[i+2] = true;
  45. checkBase[i] = false;
  46. }
  47. }
  48. }
  49. checkBase[2] = true;
  50. inx++;
  51. }
  52. else if(number[r][order[x][inx]] == 3) {
  53. for(int i=3;i>=1;i--) {
  54. if(checkBase[i]) {
  55. score++;
  56. checkBase[i] = false;
  57. }
  58. }
  59. checkBase[3] = true;
  60. inx++;
  61. }
  62. else if(number[r][order[x][inx]] == 4) {
  63. for(int i=3;i>=1;i--) {
  64. if(checkBase[i]) {
  65. score++;
  66. checkBase[i] = false;
  67. }
  68. }
  69. score++;
  70. inx++;
  71. }
  72. if(inx == 10) inx = 1;
  73. }
  74. r++;
  75. out = 0;
  76. memset(checkBase, 0, sizeof(checkBase));
  77. }
  78.  
  79. if(score > result) result = score;
  80. }
  81.  
  82. void DFS(int x) {
  83. if(x == 10) {
  84. for(int i=1;i<=9;i++) {
  85. order[o_inx][i] = p_order[i];
  86. }
  87. o_inx++;
  88. }
  89. else if(x == 4) {
  90. p_order[x] = 1;
  91. DFS(x+1);
  92. }
  93. else {
  94. for(int i=2;i<=9;i++) {
  95. if(!checkNumber[i]) {
  96. p_order[x] = i;
  97. checkNumber[i] = true;
  98.  
  99. DFS(x+1);
  100.  
  101. p_order[x] = 0;
  102. checkNumber[i] = false;
  103. }
  104. }
  105. }
  106. }
  107.  
  108. int main() {
  109. DFS(1);
  110.  
  111. scanf("%d", &t);
  112.  
  113. for(int v=1;v<=t;v++) {
  114. scanf("%d", &n);
  115.  
  116. for(int i=1;i<=n;i++) {
  117. for(int j=1;j<=9;j++) {
  118. scanf("%d", &number[i][j]);
  119. }
  120. }
  121.  
  122. for(int i=0;i<o_inx;i++) {
  123. getMax(i);
  124. }
  125.  
  126. printf("%d %d\n", v, result);
  127.  
  128. result = 0;
  129. }
  130.  
  131. return 0;
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement