#include <bits/stdc++.h>
using namespace std;
int n, m, ox, oy, endx, endy;
bool maps[50][50];
bool visited[50][50];
int action[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
int ans;
void dfs(int x, int y) {
if (x == endx && y == endy) {
ans++;
return;
}
for (int i = 0; i < 4; i++) {
int newx = x + action[i][0], newy = y + action[i][1];
if (!visited[newx][newy] && !maps[newx][newy] && newx >= 1 && newy >= 1 && newx <= n && newy <= m
) {
visited[newx][newy] = 1;
dfs(newx, newy);
visited[newx][newy] = 0;
}
}
return;
}
本人之前先在外面定义全局变量i 然后再函数里写for(i=0;i<4;i++) ,结果出错(只有40分)。
为啥这样会出错??