跳马问题

题目描述 Description

题目

输入描述 Input Description

第一行两个正整数M,N(0<M,N≤300)分别表示行和列
第二行两个正整数,表示起点的行列坐标。
第三行两个正整数,表示终点的行列坐标

输出描述 Output
Description

一个正整数,表示方案总数对123456求余{求余不知道是什么东西}

样例输入 Sample
Input

3 3

1 1

2 3

样例输出 Sample
Output

1

数据范围及提示 Data
Size & Hint

1

var m,n,x,y,b1,b2:longint;
    a:array[1..100] of longint;
    dx:array [1..4] of longint=(1,2,2,1);
    dy:array [1..4] of longint=(-2,-1,1,2);
    sum:longint=0;
procedure tiaoma(k:longint);
var i:longint;
begin
  for i:=1 to 4 do
   begin
    if ((x+dx[i]<=n)and(y+dy[i]>0)and(y+dy[i]<=n)) then
     begin
      a[k]:=i;
      x:=x+dx[i];
      y:=y+dy[i];
     if ((x=b1)and(y=b2)) then
      inc(sum)
     else tiaoma(k+1);
     x:=x-dx[i];
     y:=y-dy[i];
     end;
   end;
end;
begin
  readln(n,m);
  readln(x,y);
  readln(b1,b2);
  tiaoma(1);
  writeln(sum);
end.
时间: 2024-08-10 05:57:25

跳马问题的相关文章

N 皇后问题及跳马问题

废话不多说,先上干货. https://github.com/NeighborhoodWang/algorithm_NQueens_HorseStep/blob/master/N_queens_puzzle.cpp https://github.com/NeighborhoodWang/algorithm_NQueens_HorseStep/blob/master/horse_step.cpp 以下链接是我用C语言写的解决方案,不足之处请多指正. N皇后问题是一个很经典的问题,问题是说在一个N

国际象棋之跳马程序

问题描述: 假设国际象棋棋盘有5*5共25个格子.设计一个程序,使棋子从初始位置(棋盘格编号为1的位置)开始跳马,能够把棋盘的格子全部走一遍,每个格子只允许走一次.要求: 1) 输出一个解(用二维数组来记录马跳的过程,即[步号,棋盘格编号],左上角为第一步起点),2)求总共有多少解 棋盘格编号为: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 分析:简单的DFS... #include <stdio.h> #

【蓝桥杯】跳马问题

跳马问题.在 5*5 格的棋盘上,有一个国家象棋的马,从(1,1) 点出发,按日字跳马,它可以朝 8 个方向跳,但不允许出界或跳到已跳过 的格子上,要求在跳遍整个棋盘后再条回出发点. 输出前 5 个方案及总方案数. 输出格式示例: 1   16   21   10   25 20  11   24   15   22 17  2    19   6    9 12  7    4    23   14 3   18   13   8    5 public class Test跳马问题 { pu

Ka的回溯编程练习 Part5|跳马,又名马的遍历2

1 #include <stdio.h> 2 int TheEarthLand[6][6]={0}; 3 int HowToGoX[]={0,1,2,2,1,-1,-2,-2,-1}; 4 int HowToGoY[]={0,-2,-1,1,2,2,1,-1,-2}; 5 int total=0; 6 void op() 7 { 8 total++; 9 printf("<Way%d>:\n",total); 10 int i,j; 11 for(i=1;i&l

cogs——49. 跳马问题

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&&a

跳马问题一(C++)

#include<iostream>#include<queue> using namespace std;queue <int> x;queue <int> y;int m, n, opx, opy, edx, edy, f[110][110];int bfs(){ if((x.empty()) || (y.empty())) { cout<<"no"; exit(0); } int x1=x.front(),y1=y.fr

bzoj4417: [Shoi2013]超级跳马

裸矩阵快速幂. #include<cstdio> #define N 100 const int p=30011; int n,m; typedef int ds[N][N]; ds f,q,a; void mul(ds u,ds v){ for(int i=0;i!=n*2;++i) for(int j=0;j!=n*2;++j) a[i][j]=0; for(int i=0;i!=n*2;++i) for(int j=0;j!=n*2;++j) for(int k=0;k!=n*2;++k

BZOJ 4417 超级跳马

dp前缀和优化+矩阵快速幂. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 110 #define mod 30011 using namespace std; struct matrix { int a[maxn][maxn]; }a,b; int n,m,dp[maxn][5]; void get_table() { for (

TYVJ P1030 乳草的入侵 Label:靠输入方式坑人的水,跳马问题

背景 USACO OCT09 6TH 描述 Farmer John一直努力让他的草地充满鲜美多汁的而又健康的牧草.可惜天不从人愿,他在植物大战人类中败下阵来.邪恶的乳草已经在他的农场的西北部份佔领了一片立足之地. 草地像往常一样,被分割成一个高度為Y(1 <= y <= 100), 宽度為X(1 <= x <= 100)的直角网格.(1,1)是左下角的格(也就是说坐标排布跟一般的X,Y坐标相同).乳草一开始佔领了格(Mx,My).每个星期,乳草传播到已被乳草佔领的格子四面八方的每一