codevs1219 骑士遍历(棋盘DP)
来源:互联网 发布:360数据恢复大师免费吗 编辑:程序博客网 时间:2024/04/24 04:34
题目描述 Description
设有一个n*m的棋盘(2≤n≤50,2≤m≤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
水题,直接推就行了。。。
#include<iostream>#include<cassert>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<string>#include<iterator>#include<cstdlib>#include<vector>#include<stack>#include<map>#include<set>using namespace std;#define rep(i,f,t) for(int i = (f),_end_=(t); i <= _end_; ++i)#define rep2(i,f,t) for(int i = (f),_end_=(t); i < _end_; ++i)#define dep(i,f,t) for(int i = (f),_end_=(t); i >= _end_; --i)#define dep2(i,f,t) for(int i = (f),_end_=(t); i > _end_; --i)#define clr(c, x) memset(c, x, sizeof(c) )typedef long long int64;const int INF = 0x5f5f5f5f;const double eps = 1e-8;//*****************************************************int64 d[55][55];int main(){ int n,m,x1,x2,y1,y2; scanf("%d%d%d%d%d%d",&n,&m,&x1,&y1,&x2,&y2); if(x2 <= x1){ cout<<0<<endl; return 0; } clr(d,0); d[x1][y1] = 1; for(int i = x1; i < x2; ++i) { for(int j = 1; j <= m; ++j) { if(d[i][j]) { d[i+1][j+2] += d[i][j]; d[i+2][j+1] += d[i][j]; if(j-2 > 0) d[i+1][j-2] += d[i][j]; if(j-1 > 0) d[i+2][j-1] += d[i][j]; } } } cout<<d[x2][y2]<<endl; return 0;}
0 0
- codevs1219 骑士遍历(棋盘DP)
- codevs1219 骑士游历 棋盘型DP
- CodeVS1219 骑士游历 解题报告【棋盘型DP】
- codevs1219 骑士游历
- code(vs)1219 骑士游历 (棋盘dp)
- 骑士走棋盘问题
- 骑士走棋盘
- 骑士走棋盘
- 骑士走棋盘
- 骑士走棋盘
- 关于 马走棋盘 (骑士遍历)的深度优先算法
- 骑士旅行问题(骑士走棋盘)
- 骑士巡游 马踏棋盘
- 骑士征途(马踏棋盘)
- Algorithm Gossip:骑士走棋盘
- 算法训练-骑士走棋盘
- 骑士走棋盘(c/python)
- 骑士遍历问题
- asp.net mvc框架中,ajax传递json对象,并自动转换成参数对象的方法
- Qt QLineEdit 限制输入类型以及大小Int 和double
- BestCoder Round #20 解题报告 A.B.C.
- storm '*/stormconf.ser' does not exist 问题
- OpenVPN移植进内核了,TODO的事情实在太多
- codevs1219 骑士遍历(棋盘DP)
- 第14周 项目1 数组大折腾
- 07自定义组合控件
- 数字视频基础(一)
- Java线程(七):JUC包同步集合及JUC总结练习
- 【HDU】【P2222】【Keywords Search】【题解】【AC自动机】
- POJ 2886 Who Gets the Most Candies? (打表+线段树)
- 第14周 项目2-1 按成绩进行排名
- 黑马程序员———正则表达式