//输入m行,n列的数组,给定起点坐标x,y和终点坐标w,z,求从起点到终点的路径数。
//规定可以前后左右移动,但是下一步的值必须比当前值大。
//示例:
//输入:
//4 5
//0 0 1 0 0
//0 0 2 0 0
//0 0 3 4 0
//0 0 7 5 0
//0 2 3 2
//输出:
//2
//解法:其实就是很简单的深度优先搜索
#include <iostream>
using namespace std;
#define MAXN 60
int pic[MAXN][MAXN], vis[MAXN][MAXN] = { 0 }, rcount = 0;
int dst[4][2] = { {-1,0},{1,0},{0,-1},{0,1} };//按走上下左右的顺序
void dfs(int x, int y, int disx, int disy, int m, int n);
int main()
{
int m, n, x, y, w, z;
cin >> m >> n;
for (int i = 0; i < m; ++i)
for (int j = 0; j < n; ++j)
cin >> pic[i][j];
cin >> x >> y >> w >> z;
dfs(x, y, w, z, m, n);
cout << rcount << endl;
return 0;
}
void dfs(int x, int y, int disx, int disy, int m, int n)//传入初始坐标(x,y),终点坐标(disx,disy),矩阵大小mxn
{
if (x == disx && y == disy)
{
rcount++;
return;
}
for (int i = 0; i < 4; ++i)//枚举转移状态
{
int nextx = x + dst[i][0];
int nexty = y + dst[i][1];
if (nextx >= 0 && nexty >= 0 && nextx < m && nexty < n && pic[nextx][nexty] > pic[x][y] && vis[nextx][nexty] == 0)//能够进入下一步的条件
{
vis[nextx][nexty] = 1;//标记走过了
dfs(nextx, nexty, disx, disy, m, n);
vis[nextx][nexty] = 0;//退出来设置为没有走过,这样在回溯进行后续搜索时,不会影响对路径的搜索
}
}
return;
}