fork(1) download
  1. #include <iostream>
  2. #include <cstring>
  3. '你累吗?
  4. using namespace std;
  5.  
  6.  
  7. int ans = 0;
  8. int stack[20][8];
  9.  
  10.  
  11. void populate(int val, int *x) {
  12. for (int i = 0; i < 6; ++i) {
  13. x[i] = val % 3;
  14. val /= 3;
  15. }
  16.  
  17. }
  18.  
  19. bool consist(int *a, int *b, int *c) {
  20. for (int i = 0; i < 6; ++i) {
  21. if (a[i] != b[i] && a[i] != c[i] && b[i] != c[i]) return true;
  22. }
  23. return false;
  24. }
  25.  
  26. bool check_stack(int dep) {
  27. for (int i = 0; i < dep - 2; ++i)
  28. for (int j = i+1; j < dep - 1; ++j) {
  29. if (!consist(stack[i], stack[j], stack[dep - 1])) return false;
  30. }
  31. return true;
  32. }
  33.  
  34. void dfs(int dep, int last) {
  35. if (dep > ans) {
  36. ans = dep;
  37. cout << "Solution:" << ans << endl;
  38. for (int i = 0; i < dep; ++i) {
  39. for (int j = 0; j < 6; ++j)
  40. cout << stack[i][j];
  41. cout << endl;
  42. }
  43.  
  44. }
  45.  
  46. for (int j = last + 1; j < 729; ++j) {
  47. populate(j, stack[dep]);
  48. if (check_stack(dep + 1))
  49. dfs(dep + 1, j);
  50. }
  51. }
  52.  
  53.  
  54. int main() {
  55. populate(0, stack[0]);
  56.  
  57. int person2_choose[] = {4, 13, 40, 121};
  58. for (int i = 0; i < 4; ++i) {
  59. cout << "Now at " << i << endl;
  60. populate(person2_choose[i], stack[1]);
  61. dfs(2, i);
  62. }
  63.  
  64.  
  65. return 0;
  66. }
Time limit exceeded #stdin #stdout 5s 2728KB
stdin
Standard input is empty
stdout
Now at 0
Solution:2
000000
110000
Solution:3
000000
110000
200000
Solution:4
000000
110000
200000
120000
Solution:5
000000
110000
200000
121000
122000
Solution:6
000000
110000
200000
121000
122100
122200
Solution:7
000000
110000
200000
121000
122100
122210
122220
Solution:8
000000
110000
200000
121000
122100
122210
122221
122222
Solution:9
000000
110000
200000
121000
122110
122201
122121
122212
122022
Solution:10
000000
110000
200000
121100
122010
121201
122021
121212
122122
120222
Solution:11
000000
110000
200000
121110
122220
122101
120211
121021
121202
122012
120122
Solution:12
000000
110000
201000
120100
202010
120201
202021
120212
202122
121222
212222
022222