P1002 过河卒
题目地址:https://www.luogu.com.cn/problem/P1002
题目描述
棋盘上 AA 点有一个过河卒,需要走到目标 BB 点。卒行走的规则:可以向下、或者向右。同时在棋盘上 CC 点有一个对方的马,该马所在的点和所有跳跃一步可达的点称为对方马的控制点。因此称之为“马拦过河卒”。
棋盘用坐标表示,AA 点 (0, 0)(0,0)、BB 点 (n, m)(n,m),同样马的位置坐标是需要给出的。
#include<stdio.h>
#include<stdlib.h>
#include
#include
#define ull unsigned long long
using namespace std;
ull mat[30][30];
const int dir[8][2] = {2,1,1,2,-1,2,-2,1,-2,-1,-1,-2,1,-2,2,-1};
bool book[30][30];
void mark(int x,int y){
book[x][y] = false;
for(int i=0;i<8;i++){
int xx = x + dir[i][0];
int yy = y + dir[i][1];
book[xx][yy] = false;
}
}
int main(){
int ex,ey,mx,my;
while(scanf("%d%d%d%d",&ex,&ey,&mx,&my) == 4){
memset(mat,0,sizeof mat);
memset(book,true,sizeof book);
ex++;ey++;mx++;my++;
mark(mx,my);
mat[1][1] = 1;
for(int i=1;i<=ex;i++){
for(int j=1;j<=ey;j++){
if(!book[i][j])
continue;
mat[i][j] = max(mat[i][j],mat[i-1][j] + mat[i][j-1]);
}
}
// for(int i=1;i<=ex;i++){
// for(int j=1;j<=ey;j++){
// printf("%d “,mat[i][j]);
// }
// printf(”\n");
// }
printf("%llu\n",mat[ex][ey]);
}
return 0;
}