- 马拦过河卒
- 2014-11-06 17:32:32 @
#include<iostream>
using namespace std;
int recursion(int x,int y);
int bx,by,mx,my,s=0;
int map[21][21]={0};
int main()
{
cin>>bx>>by>>mx>>my;
for(int i=0;i<=bx;i++)
{
for(int j=0;j<=by;j++)
{
map[i][j]=1;
}
}
map[0][0]=0;
map[my][mx]=0;
map[my-1][mx-2]=0;
map[my-1][mx+2]=0;
map[my-2][mx-1]=0;
map[my-2][mx+1]=0;
map[my+1][mx-2]=0;
map[my+1][mx+2]=0;
map[my+2][mx-1]=0;
map[my+2][mx+1]=0;
recursion(0,0);
cout<<s<<endl;
return 0;
}
int recursion(int x,int y)
{
if(x==bx&&y==by) s=s+1;
else
{
if(map[x][y+1]==1) recursion(x,y+1);
if(map[x+1][y]==1) recursion(x+1,y);
}
return s;
}
1 条评论
-
524672142 LV 7 @ 2014-11-06 18:43:39
我觉得向前递归也可以啊 为什么wa呢
- 1