#include <iostream>
#include<stdlib.h>
#include<string>
#include<vector>
#include<set>
#include<math.h>
#include<map>
#include<unordered_map>
#include<algorithm>
#include<functional>
#include<queue>
#include<sstream>
typedef long long ll;
using namespace std;
int Able_Node_Num=9;//必须经过的0的个数
int counts = 0;//记录路径的个数
bool visited[3][4] = { false };
int N = 3;
int M = 4;
int grid[3][4] = {{1,0,0,0},{0,0,0,0},{0,0,2,-1}};
//四种变化,上下左右
int changes[4][2] = { {0,1},{0,-1},{1,0},{-1,0} };
void process(int x,int y,int num) {
for (int i = 0; i < 4; i++) {
int tmpx = x + changes[i][0];
int tmpy = y + changes[i][1];
//在边界范围内,且不为-1或者1;
if (tmpx >= 0 && tmpx<N&&tmpy >= 0 && tmpy<M && grid[tmpx][tmpy]!=-1&& grid[tmpx][tmpy] != 1) {
if (grid[tmpx][tmpy] == 2 ) {
if (num == Able_Node_Num) {
printf("------------grid[%d][%d]=%d num=%d\n ", x, y, grid[x][y], num);
counts++;
return;
}
//return;
}
else { //grid[tmpx][tmpy]==0
if (visited[tmpx][tmpy] == false) {
printf("grid[%d][%d]=%d num=%d\n ", tmpx, tmpy, grid[tmpx][tmpy],num+1);
visited[tmpx][tmpy] = true;
process(tmpx, tmpy, num+1); //注意和num++的区别
//还原
visited[tmpx][tmpy] = false;
}
}
}
}
}
int main() {
process(0, 0, 0);
cout << counts;
system("pause");
return 0;
}