codevs1219 骑士遍历(棋盘DP)
2014-12-01 20:35
363 查看
题目描述 Description
设有一个n*m的棋盘(2≤n≤50,2≤m≤50),如下图,在棋盘上有一个中国象棋马。
规定:
1)马只能走日字
2)马只能向右跳
问给定起点x1,y1和终点x2,y2,求出马从x1,y1出发到x2,y2的合法路径条数。
![](http://codevs.cn/media/image/problem/1219.jpg)
输入描述 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
水题,直接推就行了。。。
设有一个n*m的棋盘(2≤n≤50,2≤m≤50),如下图,在棋盘上有一个中国象棋马。
规定:
1)马只能走日字
2)马只能向右跳
问给定起点x1,y1和终点x2,y2,求出马从x1,y1出发到x2,y2的合法路径条数。
![](http://codevs.cn/media/image/problem/1219.jpg)
输入描述 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; }
相关文章推荐
- codevs1219 骑士遍历(棋盘DP)
- code(vs)1219 骑士游历 (棋盘dp)
- CodeVS1219 骑士游历 解题报告【棋盘型DP】
- codevs1219 骑士游历 棋盘型DP
- codevs 1219 骑士游历 DP 解题报告
- [CodeVs1050]棋盘染色2(状态压缩DP)
- 【动态规划】CODE[VS] 1219 骑士游历 【Noip1997】
- 棋盘型动态规划 之 CODE[VS] 1219 骑士游历 1997年
- CODE[VS] 1219 骑士游历
- CODEVS 1219骑士游历
- code vs 1029 遍历问题 区间dp
- CODE[VS] 1219 骑士游历
- codevs1010 过河卒(棋盘dp)
- 【CODEVS1219】骑士游历
- code vs 1711 棋盘分割 (dp)
- codevs1010 过河卒(棋盘dp)
- Codevs 1358 棋盘游戏(状压DP)
- code(vs)1010 过河卒 (棋盘dp)
- 【日常学习】【棋盘DP】【多线程DP】codevs1169 传纸条题解
- CODE[VS] 1219 骑士游历