using
System;
class
Program
{
static
long
[,,] dp =
new
long
[51, 51, 51];
static
long
Solver(
int
m,
int
n,
int
maxlocomote,
int
row,
int
column)
{
if
(row == m || column == n || row < 0 || column < 0)
{
return
1;
}
if
(maxlocomote == 0)
{
return
0;
}
if
(dp[row, column, maxlocomote] != 0)
{
return
dp[row, column, maxlocomote];
}
long
ways = 0;
ways += Solver(m, n, maxlocomote - 1, row - 1, column);
ways += Solver(m, n, maxlocomote - 1, row + 1, column);
ways += Solver(m, n, maxlocomote - 1, row, column - 1);
ways += Solver(m, n, maxlocomote - 1, row, column + 1);
dp[row, column, maxlocomote] = ways % 1000000007;
return
dp[row, column, maxlocomote];
}
static
int
FindPaths(
int
m,
int
n,
int
maxlocomote,
int
row,
int
column)
{
for
(
int
i = 0; i < 51; i++)
{
for
(
int
j = 0; j < 51; j++)
{
for
(
int
k = 0; k < 51; k++)
{
dp[i, j, k] = 0;
}
}
}
return
(
int
)Solver(m, n, maxlocomote, row, column);
}
static
void
Main()
{
int
m = 3, n = 3, maxlocomote = 3, row = 1, column = 1;
Console.WriteLine(FindPaths(m, n, maxlocomote, row, column));
}
}