define FOR for int void initial FOR FOR dp -1 dp bool good int int ret

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#define FOR(a, k, b) for(int a = k; a < b; a++)
void initial()
{
FOR(i, 0, n)
FOR(j, 0, m)
dp[i][j] = -1;
dp[0][0] = 1;
}
bool good(int i, int j)
{
return (i >= 0) && (j >= 0) && (i < n) && (j < m);
}
int solve(int i, int j)
{
if (good(i, j))
{
if (dp[i][j] == -1)
dp[i][j] = solve(i - 2, j - 1) + solve(i - 2, j + 1) + solve(i - 1, j - 2) + solve(i + 1, j - 2);
} else
return 0;
return dp[i][j];
}
int main()
{
initial();
printf("%d", solve(n - 1, m - 1));
return 0;
}