求求大佬了!我很快写完了然后70分,后面跟那么多答案对了一下午代码都没发现什么错!老师说过别人才能看出自己的错误,所以代码贴上
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int a[10][10],n,m,t,sx,sy,fx,fy,ans,book[10][10];
int next1[4][2] = { {1,0},{0,1},{-1,0},{0,-1} };
void dfs(int x,int y) {
if (x == fx && y == fy) {
ans++;
return;
}
else {
for (int k = 0; k <= 3; k++) {
if (a[x + next1[k][0]][y + next1[k][1]] == 1 && book[x + next1[k][0]][y + next1[k][1]] == 0) {
book[x + next1[k][0]][y + next1[k][1]] = 1;
dfs(x + next1[k][0], y + next1[k][1]);
book[x + next1[k][0]][y + next1[k][1]] = 0;
}
}
return;
}
}
int main() {
cin >> n >> m >> t;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
a[i][j] = 1;
}
}
cin >> sx >> sy;
cin >> fx >> fy;
for (int i = 0; i < t; i++) {
int tx, ty;
cin >> tx >> ty;
a[tx][ty] = 0;
}
dfs(sx, sy);
cout << ans;
return 0;
}
我对着2的数据改了一下午,输出一直都是20