Advertisement
goshansmails

Untitled

Jul 7th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. const int n = 7;
  8.  
  9. string form = "??????????????????????????????????????????????????????????????????????";
  10. vector<char> res(n * n - 1);
  11. int ans = 0;
  12. vector<vector<bool>> used(n + 2);
  13.  
  14. void rec(int idx, int r, int c) {
  15. if (used[r][c]) {
  16. return;
  17. }
  18.  
  19. if (idx < n * n - 1 && r == n && c == 1) {
  20. return;
  21. }
  22.  
  23. if (idx == n * n - 1) {
  24. if (r == n && c == 1) {
  25. ++ans;
  26. //for (int i = 0; i < n * n - 1; ++i) {
  27. // cout << res[i];
  28. //}
  29. //cout << endl;
  30. }
  31. return;
  32. }
  33.  
  34. used[r][c] = true;
  35. if (r - 1 > 0) {
  36. res[idx] = 'U';
  37. rec(idx + 1, r - 1, c);
  38. }
  39. if (r + 1 <= n) {
  40. res[idx] = 'D';
  41. rec(idx + 1, r + 1, c);
  42. }
  43. if (c - 1 > 0) {
  44. res[idx] = 'L';
  45. rec(idx + 1, r, c - 1);
  46. }
  47. if (c + 1 <= n) {
  48. res[idx] = 'R';
  49. rec(idx + 1, r, c + 1);
  50. }
  51.  
  52. /*if (form[idx] == '?') {
  53. rec(idx + 1, r - 1, c);
  54. rec(idx + 1, r + 1, c);
  55. rec(idx + 1, r, c - 1);
  56. rec(idx + 1, r, c + 1);
  57. } else if (form[idx] == 'U') {
  58. rec(idx + 1, r - 1, c);
  59. } else if (form[idx] == 'D') {
  60. rec(idx + 1, r + 1, c);
  61. } else if (form[idx] == 'L') {
  62. rec(idx + 1, r, c - 1);
  63. } else {
  64. rec(idx + 1, r, c + 1);
  65. }*/
  66.  
  67. used[r][c] = false;
  68. }
  69.  
  70. int main() {
  71. //cin >> form;
  72.  
  73. for (auto& x : used) {
  74. x.resize(n + 2, false);
  75. }
  76.  
  77. /*for (int i = 0; i < n + 2; ++i) {
  78. used[i][0] = true;
  79. used[0][i] = true;
  80. used[i][n + 1] = true;
  81. used[n + 1][i] = true;
  82. }*/
  83.  
  84. for (int i = 0; i < n + 2; ++i) {
  85. for (int j = 0; j < n + 2; ++j) {
  86. cout << used[i][j];
  87. }
  88. cout << endl;
  89. }
  90.  
  91. rec(0, 1, 1);
  92. cout << ans;
  93. return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement