洛谷1002 过河卒

题面

  • 因为出发点$A$位于$(0,0)$,所以最简单粗暴的方式就是全部往后下角挪一格,这样就不会越界。
  • Code:
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
#include<iostream>
#include<cstdio>
long long a,b,n,m,l[22][22],map[23][23];
using namespace std;
void bj(long long x,long long y){
map[x][y]=1;
map[x-1][y-2]=1;
map[x-2][y-1]=1;
map[x-2][y+1]=1;
map[x-1][y+2]=1;
map[x+1][y-2]=1;
map[x+2][y-1]=1;
map[x+2][y+1]=1;
map[x+1][y+2]=1;
return;
}
int main(){
scanf("%lld%lld%lld%lld",&n,&m,&a,&b);
bj(a,b);
l[1][0]=1;
for(int i=1;i<=n+1;++i){
for(int j=1;j<=m+1;++j){
l[i][j]=l[i-1][j]+l[i][j-1];//从上方和左方dp转移
if(map[i-1][j-1]) l[i][j]=0;//上面标记函数时没有整体往右下移,所以这里就移一下
}
}
printf("%lld",l[n+1][m+1]);
return 0;
}
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×