In general, we need an algorithm for the problem , which is written below.
Here is my idea: the idea is for O(N^2)
, the base of the dynamics is dp[0][0] = 1
, and then we simply run through the cells, and write the sum of the cell values from which we can get into this cell in each cell, i.e. dp[i][j] = dp[i - 2][j - 1] + dp[i - 2][j + 1]
...
And it does not work. I even know why, but I don’t know how to fix it.
Given a rectangular N × M board (N rows and M columns). In the upper left corner is a chess knight, which must be moved to the lower right corner of the board. In this case, a horse can only walk: 2 squares to the right and one, either up, or down, or 2 squares down and one, either to the right or to the left.
It is necessary to determine how many different routes exist leading from the upper left to the lower right corner.
Input file format
The first line of the input file contains two positive integers N and M (1 ≤ N, M ≤ 15).Output file format
In the output file output a single number of ways to get a horse to the lower right corner of the board.
Вх. данные Выход 15 14 7884330