LuoGu 1002 过河卒

题目在这里 Click me

thinking:这个月好像没怎么写题,因为我们全部都在做实验,电路、数电、离散和大物,其实还是懒,书看的还是少。
#include<cstdio>

const int maxn = 25;
int map[maxn][maxn];
int dp[maxn][maxn]; //dp[i][j]琛ㄧず浠庤捣鐐瑰埌map[i][j]鐨勮矾寰勬潯鏁?
int ex, ey, hx, hy;

void init(){
    map[hx][hy] = -1;
    map[hx-2][hy+1] = -1;
    map[hx-2][hy-1] = -1;
    map[hx-1][hy+2] = -1;
    map[hx-1][hy-2] = -1;
    map[hx+1][hy+2] = -1;
    map[hx+1][hy-2] = -1;
    map[hx+2][hy+1] = -1;
    map[hx+2][hy-1] = -1;
}

void solve(){
    init();
    for(int i = 0; i <= ex; i++)
        dp[i][0] = 0;
    for(int j = 0; j < ey; j++)
        dp[0][j] = 0;
    dp[1][1] = 1; 

    for(int i = 1; i <= ex; i++){
        for(int j = 1; j <= ey; j++){
            if(map[i][j] == -1)
                continue;
            if(dp[i-1][j] == -1 && dp[i][j-1] != -1)
                dp[i][j] = 0 + dp[i][j-1];
            else if(dp[i-1][j] != -1 && dp[i][j-1] == -1)
                dp[i][j] = dp[i-1][j] + 0;
            else if(dp[i-1][j] == -1 && dp[i][j-1] == -1)
                dp[i][j] = 0;
            else if(dp[i-1][j] != -1 && dp[i][j-1] != -1)
                dp[i][j] = dp[i-1][j] + dp[i][j-1];
            dp[1][1] = 1;
        }
    }
    printf("%d\n", dp[ex][ey]);
}

int main(){
    scanf("%d%d%d%d", &ex, &ey, &hx, &hy);
    ex = ex + 1; ey = ey + 1;
    hx = hx + 1; hy = hy + 1;
    solve();
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值