-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1010.cpp
63 lines (51 loc) · 856 Bytes
/
1010.cpp
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
题目:p1010 过河卒
*/
// dp[i][j] 表示从A点到B(i,j)点的路径数
// dp[i][j] = dp[i-1][j]+dp[i][j-1] if i-1>=0 and j-1>=0 and 且不是马的控制点
#include <iostream>
#include <cmath>
using namespace std;
int dp[20][20];
bool ControlledByHorse(int i, int j, int X, int Y)
{
if(i==X&&j==Y)
return true;
if(abs(i-X)+abs(j-Y)==3)
{
if(i-X!=0 && j-Y!=0)
return true;
}
return false;
}
void GetRoutes(int n, int m, int X, int Y)
{
int i,j;
for(i=0;i<=n;i++)
{
for(j=0;j<=m;j++)
{
if(!i && !j)
dp[i][j] = 1;
else
{
dp[i][j] = 0;
if(ControlledByHorse(i,j,X,Y))
continue;
if(i-1>=0)
dp[i][j] += dp[i-1][j];
if(j-1>=0)
dp[i][j] += dp[i][j-1];
}
}
}
}
int main()
{
int n,m,X,Y;
cin >> n >> m >> X >> Y;
GetRoutes(n,m,X,Y);
cout << dp[n][m] << endl;
return 0;
}