稍有剧透,不适者请别看(
#include <bits/stdc++.h>
using namespace std;
#define int long long
int ans[25][25],n,m,horse_x,horse_y,pyl[9][2]={{0,0},{1,2},{1,-2},{-1,2},{-1,-2},{2,1},{2,-1},{-2,1},{-2,-1}};
bool ctrl[25][25]={false};
signed main(){
cin>>n>>m>>horse_x>>horse_y;
for(int i=0;i<=9;i++){
if(horse_x+pyl[i][0]>=0&&horse_x+pyl[i][0]<=n&&horse_y+pyl[i][1]>=0&&horse_y+pyl[i][1]<=m){
ctrl[horse_x+pyl[i][0]][horse_y+pyl[i][1]]=true;
}
}
if(ctrl[0][0]||ctrl[n][m]){//
cout<<0;//
return 0;//
}//
for(int i=0;i<=n;i++){
for(int j=0;j<=m;j++){
if(ctrl[i][j]){
continue;
}
if(i){
ans[i][j]+=ans[i-1][j];
}
if(j){
ans[i][j]+=ans[i][j-1];
}
}
}
cout<<ans[n][m];
}
就是我后面打了双斜线那一块,我原来写成这样:
ans[0][0]=(ctrl[0][0]?0:1);
都没问题,我就不明白了,这题的递推式不是 Ansx,y=Ansx−1,y+Ansx,y−1(大概长这样) 吗,那么既然 Ans0,0 都为 0 了,那其他所有的推出来不都是 0 吗,而且如果终点被马控制了,那肯定也到不了,应该输出 0 啊,我像最上面这么写,就全错,下载了数据后,发现输出的结果和AC代码的结果是一样的,真搞不懂了,大佬求教(哭,急)