洛谷 P1002 过河卒

题目描述

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

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

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

输入输出格式

输入格式:

一行四个数据,分别表示B点坐标和马的坐标。

输出格式:

一个数据,表示所有的路径条数。

输入输出样例

输入样例#1:
6 6 3 3
输出样例#1:
6

说明

结果可能很大!

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 
 5 using namespace std;
 6 
 7 const int N=120;
 8 
 9 int t=10;//fang zhi tiao dao fu shu 
10 long long dp[N][N],b[N][N],c[N][N],n,m,x,y;
11 
12 inline void read(long long & x)
13 {
14     char c=getchar();
15     x=0;
16     while(c<'0'&&c>'9')c=getchar();
17     while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
18 }
19 
20 int main()
21 {
22     read(n);
23     read(m);
24     read(x);
25     read(y);
26     c[x+t][y+t]=1;
27     c[x-2+t][y+1+t]=1;
28     c[x+2+t][y+1+t]=1;
29     c[x-1+t][y+2+t]=1;
30     c[x+1+t][y+2+t]=1;
31     c[x-2+t][y-1+t]=1;
32     c[x+2+t][y-1+t]=1;
33     c[x-1+t][y-2+t]=1;
34     c[x+1+t][y-2+t]=1;
35     dp[t][t-1]=1;
36     for(int i=t;i<=n+t;i++)
37     {
38         for(int j=t;j<=m+t;j++)
39              {
40              if(c[i][j]!=1)
41              {
42                 dp[i][j]=dp[i-1][j]+dp[i][j-1];
43              }
44         }
45     }
46     printf("%lld",dp[t+n][t+m]);
47     return 0;
48 }
原文地址:https://www.cnblogs.com/lyqlyq/p/6875284.html