一道简单的 dfs 题。
#include <cstdio>
using namespace std;
const int maxn=12;
int map[maxn][maxn],
line_size, col_size, stone_size,
beg_line, beg_col, end_line, end_col,
cnt_ans=0;
void dfs(int line, int col){
if(line<1 || line>line_size
|| col<1 || col>col_size
|| map[line][col]){ return; }
if(line==end_line && col==end_col){
++cnt_ans;
}
map[line][col]= true;
dfs(line+1, col);
dfs(line-1, col);
dfs(line, col+1);
dfs(line, col-1);
map[line][col]= false;
}
void print(){
for(int line=1; line<=line_size; ++line){
for(int col=1; col<=col_size; ++col){
int ch= map[line][col];
if(ch) putchar('#');
else putchar('@');
}
putchar('\n');
}
}
int main(){
scanf("%d%d%d", &line_size, &col_size, &stone_size);
scanf("%d%d%d%d", &beg_col, &beg_line, &end_col, &end_line);
for(int i=1; i<=stone_size; ++i){
int line, col;
scanf("%d%d", &col, &line);
map[line][col]= true;
}
//printf("%d %d %d %d\n", beg_line, beg_col, end_line, end_col);
//print();
dfs(beg_line, beg_col);
printf("%d\n", cnt_ans);
return 0;
}