49. 跳马问题 http://cogs.pro:8080/cogs/problem/problem.php?pid=49
水题
dfs 裸基础
- #include<cstdio>
- using namespace std;
- int n,m,mx[5]={0,1,1,2,2},
- ans,my[5]={0,-2,2,-1,1};
- inline void dfs(int x,int y){
- if(x==m&&y==n){ ans++; return;}
- for(int i=1;i<=4;i++){
- int tx=mx[i]+x,ty=my[i]+y;
- if(tx>0&&ty>0&&tx<=m&&ty<=n)
- dfs(tx,ty);
- }
- }
- int main()
- {
- freopen("horse.in","r",stdin);
- freopen("horse.out","w",stdout);
- scanf("%d%d",&n,&m);
- dfs(1,1);
- printf("%d",ans);
- return 0;
- }
来源: http://www.bubuko.com/infodetail-2763121.html