http://www.luogu.org/problem/show?pid=1605
求方案数用DFS。
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ms(i,j) memset(i,j, sizeof i);
using namespace std;
const int dx[4] = {1,0,-1,0},
dy[4] = {0,1,0,-1};
int vi[10][10];
int n,m,t;
int ans = 0;
int sx, sy, fx, fy;
int dfs(int x, int y)
{
if (x==fx&&y==fy) {ans++; return 0;}
for (int i=0;i<4;i++)
{
int tx = x + dx[i], ty = y + dy[i];
if (tx>0&&tx<=n&&ty>0&&ty<=m&&vi[tx][ty]==0)
{
vi[tx][ty] = 1;
dfs(tx,ty);
vi[tx][ty] = 0;
}
}
return 0;
}
int main()
{
ms(vi, 0);
scanf("%d%d%d%d%d%d%d", &n, &m, &t, &sx, &sy, &fx, &fy);
for (int i=1;i<=t;i++)
{
int a,b;
scanf("%d%d", &a, &b);
vi[a][b] = -1;
}
vi[sx][sy] = -1;
dfs(sx,sy);
printf("%d\n", ans);
return 0;
}