@[spacetar](/user/779486) 没考虑`i==0&&j!=0`和`i!=0&&j==0`的情况
by DreamLand_zcb @ 2023-02-03 21:20:21
@[spacetar](/user/779486)
```cpp
if(i == 0 && j == 0) continue;
else if(i == 0 && j > 0)
{
dp[i][j]=dp[i][j-1];
}
else if(j == 0 && i > 0)
{
dp[i][j]=dp[i-1][j];
}
else
{
dp[i][j]=dp[i-1][j]+dp[i][j-1];
}
```
by DreamLand_zcb @ 2023-02-03 21:22:04
@[DreamLand_zcb](/user/778011)
```cpp
if(i>0){
dp[i][j]+= dp[i-1][j];
}
if(j>0){
dp[i][j]+= dp[i][j-1];
}
```
这串代码可以实现相应功能吗?
by spacetar @ 2023-02-03 21:30:44
@[spacetar](/user/779486)
```cpp
if(i==0){
dp[i][j]+= dp[i][j-1];
}
if(j==0){
dp[i][j]+= dp[i-1][j];
}
```
by DreamLand_zcb @ 2023-02-03 21:36:29
@[spacetar](/user/779486) 这样也可以,不如直接
```cpp
else
{
dp[i][j]=dp[i-1][j]+dp[i][j-1];
}
```
再加上刚才那个
by DreamLand_zcb @ 2023-02-03 21:37:27
@[spacetar](/user/779486) 但是你这么写没有考虑边界情况
by DreamLand_zcb @ 2023-02-03 21:38:23
```cpp
#include <iostream>
using namespace std;
long long f[22][22];
bool ctrl[22][22];
int n, m, x, y;
int d[9][2] = {2,1,1,2,-1,2,-2,1,-2,-1,-1,-2,1,-2,2,-1};
int main(){
cin>>n>>m>>x>>y;
for (int i = 0;i<=8;i++){
int tx = x+d[i][0], ty = y+d[i][1];
if (tx>=0&&ty>=0&&tx<=n&&ty<=m){
ctrl[tx][ty] = true;
}
}
if (ctrl[0][0]) {
cout<<0;
return 0;
}
f[0][0] = 1;
for (int i = 0;i<=n;i++)
for (int j = 0;j<=m;j++){
if(ctrl[i][j]) continue;
if (i) f[i][j]+=f[i-1][j];
if (j) f[i][j]+=f[i][j-1];
}
cout<<f[n][m];
return 0;
}
```
by Tx1234567 @ 2023-02-06 08:24:06