问题:
难度:普及-
说明:
具体还是去洛谷看吧:https://www.luogu.com.cn/problem/P1002。
一个从(0,0)的卒要到达指定位置,其中有个马拦截,马自身(不能吃)和他的攻击点都不能到达,然后求到达位置路径数。
输入范围:
对于 %100% 的数据,1 ≤ n,m ≤ 20,0 ≤ 马的坐标 ≤ 20。
输入案例:
// 简单画个图就知道了
输入
6 6 3 3
输出
6
我的代码:
司空见惯的dp题目,用dfs肯定不是mle就是tle,我放一个dp的做法,再下面再放一个dfs MLE代码(不要浪费)
/**
* P1002
*/
public class P1002_House {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] input = new int[4];
for(int i = 0;i < 4;i++) {
input[i] = sc.nextInt();
}
addBad(input[0], input[1], input[2], input[3]);
//System.out.println(dfs(input[0], input[1]));
System.out.println(dp(input[0], input[1]));
//System.out.print(dfs(20, 20, 3, 3));
}
static int[][] bad = new int[9][2];
static int badindex = -1;
static int badcount = -1;
static boolean needCheck = true;
public static long dp(int bx, int by) {