2390: Tired Horse

本文探讨了在一个m*n的棋盘上,从指定起始位置出发,骑士能以多少种不同路径返回起点的问题。通过深度优先搜索算法,实现了一个递归解决方案,并提供了一个具体的示例输入和输出。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2390: Tired Horse


ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE
3s8192K16889Standard

On a chess board sizes of m*n(1<=m<=5,1<=n<=5),given a start position,work out the amount of all the different paths through which the horse could return to the start position.(The position that the horse passed in one path must be different.The horse jumps in a way like "日")

Input

The input consists of several test cases.The size of the chess board m,n(row,column),and the start position v,h(vertical , horizontal) ,separated by a space.The left-up point is (0,0)

Output

the amount of the paths in a single line

Sample Input

5 4 3 1

Sample output

4596

 

Problem Source: provided by slp3

 


This problem is used for contest: 82 

 

#include<stdio.h>
#include<string.h>
int map[10][10];
int row,colum,gi,gj;
int xx[8]={1,2, 2, 1,-1,-2,-2,-1};
int yy[8]={2,1,-1,-2,-2,-1,1,2};
int count;
void dfs(int x,int y)
{
 if(map[x][y])
 {
 if(x==gi&&y==gj) count++;
 return ;
 }
 int i;
 map[x][y]=1;
 for(i=0;i<8;i++)
 {
  if(x+xx[i]<0||x+xx[i]>=row||y+yy[i]<0||y+yy[i]>=colum) continue;
  dfs(x+xx[i],y+yy[i]);
 }
 map[x][y]=0;
}
 
int main()
{
 int i;
 while(scanf("%d%d%d%d",&row,&colum,&gi,&gj)==4)
 {
  memset(map,0,sizeof(map));
  count=0;
  dfs(gi,gj);
  printf("%d/n",count);
 }
 return 0;
}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值