3\4WA,求调
查看原帖
3\4WA,求调
1808187
SnowStream楼主2025/8/4 20:24

如标题,都给AI分析了,就是过不了3、4,调了几次看不出原因,我人麻了

#include<bits/stdc++.h>
using namespace std;
long long dp[21][21];
bool board[21][21]={false};
int n,m,cx,cy;
void setb(int x, int y) {
    if (x >= 0 && x <= n && y >= 0 && y <= m)board[x][y] = true;
    return;
}
void search(int x,int y){
    if(dp[x][y]!=-1)return;
    if(board[x][y]){dp[x][y]=0;return;}
    if(x==0||y==0){dp[x][y]=1;return;}
    search(x-1,y);
    search(x,y-1);
    dp[x][y]=dp[x-1][y]+dp[x][y-1];
    return;
}
int main() {
    memset(dp,-1,sizeof dp);
    cin>>n>>m>>cx>>cy;
    setb(cx-2,cy-1);
    setb(cx-2,cy+1);
    setb(cx+2,cy-1);
    setb(cx+2,cy+1);
    setb(cx-1,cy-2);
    setb(cx-1,cy+2);
    setb(cx+1,cy-2);
    setb(cx+1,cy+2);
    setb(cx,cy);
    search(n,m);
    cout<<dp[n][m];
    return 0;
}
2025/8/4 20:24
加载中...