【洛谷】P1002 过河卒

#include
#include
using namespace std;
short n,m,horse_x,horse_y;
long long checkerboard[103][103];
long long road[103][103];
void sign(short x,short y){
    checkerboard[x][y]=1;
    checkerboard[x-1][y-2]=1;
    checkerboard[x-2][y-1]=1;
    checkerboard[x-2][y+1]=1;
    checkerboard[x-1][y+2]=1;
    checkerboard[x+1][y-2]=1;
    checkerboard[x+2][y-1]=1;
    checkerboard[x+2][y+1]=1;
    checkerboard[x+1][y+2]=1;
}
void input(){
    scanf("%d %d %d %d",&n,&m,&horse_x,&horse_y);
    sign(horse_x,horse_y);
}
void solve(){
    int i,j;
    road[-1][0]=1;
    for(i=0;i<=n;++i){
        for(j=0;j<=m;++j){
            road[i][j]=road[i-1][j]+road[i][j-1];
            if(checkerboard[i][j])
                road[i][j]=0;
        }
    }
}
void output(){
    printf("%lld",road[n][m]);
}
int main(){
    input();
    solve();
    output();
    return 0;
}

你可能感兴趣的:(洛谷)