Advertisement
msu_goncharenko

Untitled

Dec 2nd, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3.  
  4. bool possible (const int, const int, const int);
  5. void rec (const int, const int);
  6.  
  7. const int size = 15;
  8. int arr[size][size] = {0}, Row, Column;
  9.  
  10. int main() {
  11. std::cin >> Row >> Column;
  12. if ((Row + Column) < 5) {
  13. std::cout << 0;
  14. return 0;
  15. }
  16. arr[0][0] = 1;
  17. rec (0, 0);
  18. std::cout << arr[Row - 1][Column - 1];
  19. return 0;
  20. }
  21.  
  22. bool possible (const int course, const int cur_i, const int cur_j) {
  23. switch (course) {
  24. case 1:
  25. return ((cur_i > 0) && (cur_j < Column - 2));
  26. break;
  27. case 2:
  28. return ((cur_i < Row - 1) && (cur_j < Column - 2));
  29. break;
  30. case 3:
  31. return ((cur_i < Row - 2) && (cur_j < Column - 1));
  32. break;
  33. case 4:
  34. return ((cur_i < Row - 2) && (cur_j > 0));
  35. break;
  36. default:
  37. return 0;
  38. }
  39. }
  40.  
  41. void rec (const int i, const int j) {
  42. if ((i == Row - 1) && (j == Column - 1))
  43. return;
  44.  
  45. if (possible (1, i, j)) {
  46. arr[i - 1][j + 2] += arr[i][j];
  47. rec (i - 1, j + 2);
  48. }
  49. if (possible (2, i, j)) {
  50. arr[i + 1][j + 2] += arr[i][j];
  51. rec (i + 1, j + 2);
  52. }
  53. if (possible (3, i, j)) {
  54. arr[i + 2][j + 1] += arr[i][j];
  55. rec (i + 2, j + 1);
  56. }
  57. if (possible (4, i, j)) {
  58. arr[i + 2][j - 1] += arr[i][j];
  59. rec (i + 2, j - 1);
  60. }
  61. arr[i][j] = 0;
  62.  
  63. return;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement