zoukankan      html  css  js  c++  java
  • codevs1219 骑士游历

    题目描述 Description

    设有一个n*m的棋盘(2≤n≤50,2m≤50),如下图,在棋盘上有一个中国象棋马。

    规定:

    1)马只能走日字

    2)马只能向右跳

    问给定起点x1,y1和终点x2,y2,求出马从x1,y1出发到x2,y2的合法路径条数。

    输入描述 Input Description

    第一行2个整数n和m

    第二行4个整数x1,y1,x2,y2

    输出描述 Output Description

    输出方案数

    样例输入 Sample Input

    30 30

    1 15 3 15

    样例输出 Sample Output

    2

    数据范围及提示 Data Size & Hint

    2<=n,m<=50

    最近很颓……在做sb题

    因为没开long long还wa了一次

    话说codevs的天梯还真是有趣啊……我都到黄金组了

    #include<cstdio>
    #define LL long long
    const int mx[4]={1,2,2,1};
    const int my[4]={2,1,-1,-2};
    LL f[60][60];
    int n,m,x1,x2,y1,y2;
    int main()
    {
    	scanf("%d%d",&n,&m);
    	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
    	f[x1][y1]=1;
    	for (int i=1;i<=n;i++)
    	  for (int j=1;j<=m;j++)
    		for (int k=0;k<4;k++)
    		  {
    		  	int nx=i+mx[k];
    		  	int ny=j+my[k];
    		  	if (nx<1||nx>n||ny<1||ny>m)continue;
    		  	f[nx][ny]+=f[i][j];
    		  }
    	printf("%lld
    ",f[x2][y2]);
    }
    

      

    ——by zhber,转载请注明来源
  • 相关阅读:
    C++的高效从何而来2
    初体验ajax跨域
    ACM在线测评系统评测程序设计与实现
    高效GTD云工具 Manage Your Time
    HTTP 长连接
    使用avalon MVVM框架打造整一套jquery ui
    GhostDoc(注释生成工具)使用方法
    NUnit快速入门 笔记
    ETags
    nodejs + edge + ejs + c#
  • 原文地址:https://www.cnblogs.com/zhber/p/4035909.html
Copyright © 2011-2022 走看看