Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- bool possible (const int, const int, const int);
- void rec (const int, const int);
- const int size = 15;
- int arr[size][size] = {0}, Row, Column;
- int main() {
- std::cin >> Row >> Column;
- if ((Row + Column) < 5) {
- std::cout << 0;
- return 0;
- }
- arr[0][0] = 1;
- rec (0, 0);
- std::cout << arr[Row - 1][Column - 1];
- return 0;
- }
- bool possible (const int course, const int cur_i, const int cur_j) {
- switch (course) {
- case 1:
- return ((cur_i > 0) && (cur_j < Column - 2));
- break;
- case 2:
- return ((cur_i < Row - 1) && (cur_j < Column - 2));
- break;
- case 3:
- return ((cur_i < Row - 2) && (cur_j < Column - 1));
- break;
- case 4:
- return ((cur_i < Row - 2) && (cur_j > 0));
- break;
- default:
- return 0;
- }
- }
- void rec (const int i, const int j) {
- if ((i == Row - 1) && (j == Column - 1))
- return;
- if (possible (1, i, j)) {
- arr[i - 1][j + 2] += arr[i][j];
- rec (i - 1, j + 2);
- }
- if (possible (2, i, j)) {
- arr[i + 1][j + 2] += arr[i][j];
- rec (i + 1, j + 2);
- }
- if (possible (3, i, j)) {
- arr[i + 2][j + 1] += arr[i][j];
- rec (i + 2, j + 1);
- }
- if (possible (4, i, j)) {
- arr[i + 2][j - 1] += arr[i][j];
- rec (i + 2, j - 1);
- }
- arr[i][j] = 0;
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement