题解 | #[NOIP2002]过河卒#

[NOIP2002]过河卒

https://ac.nowcoder.com/acm/problem/16708

整体++,方便写dp。不开LL60分。


const int N = 2e2 + 21;
LL f[N][N];
int vis[N][N];
void inpfile();
void solve() {
    int n,m; cin>>n>>m;
    int tx,ty; cin>>tx>>ty;
    n++,m++,tx++,ty++;
    vector<int> fx({-1,-1,-2,-2,1,1,2,2}), fy({-2,2,1,-1,2,-2,1,-1});
    vis[tx][ty] = 1;
    for(int i = 0; i < 8; ++i) {
        int xx = tx + fx[i], yy = ty + fy[i];
        if(xx < 1 || xx > n || yy < 1 || yy > m) continue;
        vis[xx][yy] = 1;
    }
    f[1][1] = 1;
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= m; ++j) {
            if(vis[i][j]) f[i][j] = 0;
            else f[i][j] += f[i][j-1] + f[i-1][j];
        }
    }
    cout<<f[n][m];
}
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务