LuoGu 1002 过河卒

来源:互联网 发布:鉴知往来的意思 编辑:程序博客网 时间:2024/06/07 08:11

题目在这里 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;}
原创粉丝点击