标签:des style blog http color io os ar java
6 6 3 3
6
sad 写了好久。。接近一个小时,一开始居然把马的范围初始化错了。。
首先生成地图,然后挂掉马的范围(8个点) ,然后爆搜就可以了。
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#define ll long long
using namespace std;
const int INF = 0x3f3f3f3f;
int n,m,ex,ey,ans,ma[20][20];
bool vis[20][20];
void dfs(int x,int y)
{
if(x==n&&y==m)
{
ans++;
return ;
}
if(x+1<=n&&ma[x+1][y]&&!vis[x+1][y])
{
vis[x+1][y]=1;
dfs(x+1,y);
vis[x+1][y]=0;
}
if(y+1<=m&&ma[x][y+1]&&!vis[x][y+1])
{
vis[x][y+1]=1;
dfs(x,y+1);
vis[x][y+1]=0;
}
}
int main()
{
memset(vis,0,sizeof(vis));
scanf("%d%d%d%d",&n,&m,&ex,&ey);
ans=0;
for(int i=0;i<=n;i++)
for(int j=0;j<=m;j++)
ma[i][j]=1;
if(ex-1>=0&&ex-1<=n&&ey-2>=0&&ey-2<=m)ma[ex-1][ey-2]=0;
if(ex-1>=0&&ex-1<=n&&ey+2>=0&&ey+2<=m)ma[ex-1][ey+2]=0;
if(ex+1>=0&&ex+1<=n&&ey-2>=0&&ey-2<=m)ma[ex+1][ey-2]=0;
if(ex+1>=0&&ex+1<=n&&ey+2>=0&&ey+2<=m)ma[ex+1][ey+2]=0;
if(ex+2>=0&&ex+2<=n&&ey-1>=0&&ey-1<=m)ma[ex+2][ey-1]=0;
if(ex+2>=0&&ex+2<=n&&ey+1>=0&&ey+1<=m)ma[ex+2][ey+1]=0;
if(ex-2>=0&&ex-2<=n&&ey+1>=0&&ey+1<=m)ma[ex-2][ey+1]=0;
if(ex-2>=0&&ex-2<=n&&ey-1>=0&&ey-1<=m)ma[ex-2][ey-1]=0;
if(ex>=0&&ex<=n&&ey>=0&&ey<=m)ma[ex][ey]=0;
vis[0][0]=1;
dfs(0,0);
printf("%d\n",ans);
return 0;
}
标签:des style blog http color io os ar java
原文地址:http://blog.csdn.net/qq_16255321/article/details/40402977