SWJTUOJ-2366 A chess Problem (easy)
来源:互联网 发布:形容网络喷子 编辑:程序博客网 时间:2024/06/08 14:35
A chess Problem (easy)
发布时间: 2017年5月7日 17:10 最后更新: 2017年5月7日 17:13 时间限制: 2000ms 内存限制: 128M
In chinese chess, "马" is an interesting piece, when it is at position
Now the problem is, when a “马” is at position
To simplify this problem, when our "马" is at
The first line: the number of case
Then T lines follow, each line contains four integers:
For each case, out put an integer
30 0 3 30 0 6 63 3 6 6
262
一道跳马题,求路径数,很容易想到DFS,数据不大,可以直接深搜。
当然在此基础上可以用DP,因为只有两种跳法,也可以用数学排列组合的方法,计算出终点和起点的横纵坐标之差的绝对值,可以算出(2,1)和(1,2)两种走法各自的步数,然后用排列组合解决,注意判断到不了的情况,输出0。
因为我用的DFS,剩下两种方法没写,就不贴了_(:з」∠)_。
#include "iostream"#include "cstdlib"#include "cstdio"#include "cmath"#include "cstring"using namespace std;int sx,sy,ex,ey;int ans;void dfs(int x,int y){ if(x>8 || y>8 || x<0 || y<0) return ; if(x==ex && y==ey) { ans++; return ; } else { dfs(x+2,y+1); dfs(x+1,y+2); }}int main(){ int t; cin >> t; while(t--) { cin >> sx >> sy >> ex >> ey; ans=0; dfs(sx,sy); cout << ans << endl; } return 0;}
- SWJTUOJ-2366 A chess Problem (easy)
- SWJTUOJ-2364 A room Problem(easy)
- SWJTUOJ-2397 A Easy Counting Problem
- swjtuoj 2380 Knapsack Problem
- swjtuoj 2383 Music Problem
- SetType,a easy problem
- A problem is easy
- A problem is easy
- A problem is easy
- A problem is easy
- csu A Easy Problem
- A problem is easy
- A problem is easy
- A problem is easy
- A problem is easy
- poj-1152 a easy problem
- NYOJ - A problem is easy
- NYOJ - A problem is easy
- java学习之鸡兔同笼
- Android Input系统的启动以及Input场景下的ANR
- Valid Sudoku
- WebService开发服务端
- java学习之接口和抽象类
- SWJTUOJ-2366 A chess Problem (easy)
- 关于学习安卓相关的文章与教学平台
- 排序算法——插入排序(Insertion Sort)
- pano-on入门
- 番茄工作法自我实践
- test
- SQL高级语法——DML
- python实例手册
- Android WiFi--系统架构