题目:
左上角走到右下角,*表示能走,#表示不能走,求方案数
第一行n与m
接下来是一个由*与#组成的迷宫
每次都出0的代码;
#include<bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0 ,0};
int n, m;
int ans = 0;
char puz[10][10];
void dfs(int x, int y, int step){
if(x==n && y==m){
ans += 1;
return;
}
for(int i=0;i<4;i++){
int tx = x+dx[i];
int ty = y+dy[i];
if(tx<1 || tx>n || ty<1 || ty>m || puz[tx][ty] == '#'){
continue;
}
puz[tx][ty] = '#';
dfs(tx,ty, step+1);
puz[tx][ty] = '*';
}
}
int main(){
int n, m;
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>puz[i][j];
}
}
puz[1][1] = '#';
dfs(1, 1, 0);
cout<<ans;
return 0;
}