P1002 [NOIP2002 普及组] 过河卒
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
int Horse_y[8] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int Horse_x[8] = { 1, 2, 2, 1, -1, -2, -2, -1 };
int x_destination, y_destination, x_horse, y_horse;
scanf("%d %d %d %d", &x_destination, &y_destination, &x_horse, &y_horse);
int board[x_destination + 1][y_destination + 1];
memset(board, 0, sizeof(board));
long long methods[x_destination + 1][y_destination + 1];
memset(methods, 0, sizeof(methods));
board[x_horse][y_horse] = 1;
for (int i = 0; i < 8; i++) {
int x_jump = x_horse + Horse_x[i];
int y_jump = y_horse + Horse_y[i];
if (x_jump < 0 || x_jump > x_destination || y_jump < 0 || y_jump > y_destination)
continue;
board[x_jump][y_jump] = 1;
}
methods[0][0] = 1;
for (int i = 0; i <= x_destination && board[i][0] == 0; i++)
methods[i][0] = 1;
for (int j = 0; j <= y_destination && board[0][j] == 0; j++)
methods[0][j] = 1;
for (int i = 1; i <= x_destination; i++)
for (int j = 1; j <= y_destination; j++) {
if (board[i][j] == 1)
continue;
methods[i][j] = methods[i - 1][j] + methods[i][j - 1];
}
printf("%lld", methods[x_destination][y_destination]);
system("pause");
return 0;
}
标签:horse,洛谷,methods,NOIP2002,int,destination,P1002,jump,board
From: https://www.cnblogs.com/fjnhyzCYL/p/17061995.html