-
题目链接
P1002 过河卒 -
思路
①棋盘中一点走法为该点上方点走法+该点左侧点走法,即way[x][y] = way[x - 1][y] + way[x][y - 1] ②对方马的控制点走法为0
-
样例棋盘
1 1 1 1 1 1 1
1 2 x 1 x 1 2
1 x 0 1 1 x 2
1 1 1 x 1 1 3
1 x 1 1 2 x 3
1 1 x 1 x 0 3
1 2 2 3 3 3 6 -
代码
#include<stdio.h>
unsigned long long bd[21][21];
int h[9][2];
void horsepoint() {
h[4][0] = h[5][0] = h[0][0] - 2;
h[3][0] = h[6][0] = h[0][0] - 1;
h[2][0] = h[7][0] = h[0][0] + 1;
h[1][0] = h[8][0] = h[0][0] + 2;
h[6][1] = h[7][1] = h[0][1] - 2;
h[5][1] = h[8][1] = h[0][1] - 1;
h[1][1] = h[4][1] = h[0][1] + 1;
h[2][1] = h[3][1] = h[0][1] + 2;
}//对方马的控制点
int horse(int x, int y) {
for (int i = 0; i < 9; i++)
if (x == h[i][0] && y == h[i][1])
return 1;
return 0;
}//判断该点是否为马的控制点
int main()
{
int bx, by;
scanf("%d%d%d%d", &bx, &by, &h[0][0], &h[0][1]);
horsepoint();
for (int x = 0; x <= bx; x++)
for (int y = 0; y <= by; y++)
bd[x][y] = 0;
bd[0][0] = 1;//(0,0)点初始为一种走法
for (int x = 0; x <= bx; x++)
for (int y = 0; y <= by; y++)
{
if (x == 0 && y == 0)
continue;
if (horse(x, y))//跳过马点
continue;
if (x)
bd[x][y] += bd[x - 1][y];//累加上方点走法
if (y)
bd[x][y] += bd[x][y - 1];//累加左侧点走法
}
/*for (int x = 0; x <= bx; x++)
{
for (int y = 0; y <= by; y++)
printf("%llu ", bd[x][y]);
puts("");
}*/
printf("%llu", bd[bx][by]);
return 0;
}