代码:
#include <bits/stdc++.h>
using namespace std;
int a[21][21]
= {0};
void soldier(){
int i, j, m, n, x, y;
cin >> n >> m
>> x >> y;
if(true){
a[x][y]
= -1;
if(x
- 1 >=
0 && y -
2 >= 0) a[x-1][y-2]
= -1;
if(x
- 2 >=
0 && y -
1 >= 0) a[x-2][y-1]
= -1;
if(x
- 2 >=
0 && y +
1 <= m-1) a[x-2][y+1]
= -1;
if(x
- 1 >=
0 && y +
2 <= m-1) a[x-1][y+2]
= -1;
if(x
+ 1 <= n
&& y + 2
<= m) a[x+1][y+2]
= -1;
if(x
+ 2 <= n
&& y + 1
<= m) a[x+2][y+1]
= -1;
if(x
+ 2 <= n
&& y - 1
>= 0) a[x+2][y-1]
= -1;
if(x
+ 1 <= n
&& y - 2
>= 0) a[x+1][y-2]
= -1;
}
for(i
= 0; i
<= n; i++){
for(j
= 0; j
<= m; j++)
{
if(a[i][j]
== -1)
continue;
if(i
== 0 && j
== 0)
{a[i][j]
= 1;
continue;
}
a[i][j]
= 0;
if(j-1
>= 0
&& a[i][j-1]
!= -1)
a[i][j]
+= a[i][j-1];
if(i-1
>= 0
&& a[i-1][j]
!= -1)
a[i][j]
+= a[i-1][j];
if(a[i][j]
== 0) a[i][j]
= -1;
}
}
if(a[n][m]==
-1) cout
<< 0;
else cout << a[n][m];
}
int main(){
soldier();
return 0;
}
分析:
将马的点和控制点设为-1,起始点设为1,然后判断周围是否为控制点,不是的话加一,是的话则为0;