ACM_JLINE.

矩阵取数游戏

字数统计: 435阅读时长: 2 min
2019/03/07 Share

矩阵取数游戏

原题链接:传送门

昨天的太难了 今天才想明白 状态转移应该没问题, 后面懒得搞大数了

题目大意

棋盘上 A 点有一个过河卒,需要走到目标 B 点。卒行走的规则:可以向下、或者向右。同时在棋盘上 C 点有一个对方的马,该马所在的点和所有跳跃一步可达的点称为对方马的控制点。因此称之为“马拦过河卒”。

棋盘用坐标表示,A点(0, 0) 、B点(n, m) (n, m为不超过20的整数),同样马的位置坐标是需要给出的。

现在要求你计算出卒从A点能够到达B点的路径的条数,假设马的位置是固定不动的,并不是卒走一步马走一步。

题解

签到题 注意别越界

Code block

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
using namespace std;

int a[25][25];
int dx[] = {-2, -2, -1, -1, 1, 1, 2, 2};
int dy[] = {1, -1, -2, 2, 2, -2, -1, 1};
int sx, sy, ex, ey;
long long num[25][25];

int main(){
scanf("%d%d%d%d", &sx, &sy, &ex, &ey);

for(int i = 0; i < 8; i++){
int tx = ex + dx[i];
int ty = ey + dy[i];
if(tx >= 0 && tx <= sx && ty >= 0 && ty <= sy)
a[tx][ty] = 1;
}

a[ex][ey] = 1;

num[0][0] = 1;
for(int i = 0; i <= sx; i++){
for(int j = 0; j <= sy; j++){
if(a[i][j] == 0) {
if(i > 0)
num[i][j] += num[i-1][j];
if(j > 0)
num[i][j] += num[i][j-1];
}
}
}

// for(int i = 0; i <= sx; i++){
// for(int j = 0; j <= sy; j++){
// printf("%d ", num[i][j]);
// }
// printf("\n");
// }
//
printf("%lld\n", num[sx][sy]);
return 0;
}
CATALOG
  1. 1. 矩阵取数游戏
    1. 1.1. 原题链接:传送门
      1. 1.1.1. 题目大意:
      2. 1.1.2. 题解:
      3. 1.1.3. Code block