• 【洛谷 1002】 过河卒


    题目描述

    棋盘上AA点有一个过河卒,需要走到目标BB点。卒行走的规则:可以向下、或者向右。同时在棋盘上CC点有一个对方的马,该马所在的点和所有跳跃一步可达的点称为对方马的控制点。因此称之为“马拦过河卒”。

    棋盘用坐标表示,AA点(0, 0)(0,0)、BB点(n, m)(n,m)(nn, mm为不超过2020的整数),同样马的位置坐标是需要给出的。

    现在要求你计算出卒从AA点能够到达BB点的路径的条数,假设马的位置是固定不动的,并不是卒走一步马走一步。

    输入输出格式

    输入格式:
    一行四个数据,分别表示BB点坐标和马的坐标。

    输出格式:
    一个数据,表示所有的路径条数。

    输入输出样例

    输入样例#1: 复制
    6 6 3 3
    输出样例#1: 复制
    6
    说明

    结果可能很大!

    题解:哇我居然没写过这道题……普通的二维DP啦,不过得考虑负数情况,所以集体位移1.初始设置应该是ans[1][0]=1而不是ans[1][1]=1;检查了好久!!!

    代码:

    #include<cstdio>
    #include<iostream>
    #include<cmath>
    #include<cstdlib>
    #include<cstring>
    #include<algorithm>
    typedef long long ll;
    using namespace std;
    ll x1,t1,x2,y2;
    int f[29][29]; 
    ll ans[25][25];
    int main(){
        
        cin>>x1>>t1>>x2>>y2;
        x1++; x2++; t1++; y2++;
        
        f[x2][y2]=-1;
        f[x2-1][y2-2]=-1;
        f[x2-2][y2-1]=-1;
        f[x2-2][y2+1]=-1;
        f[x2-1][y2+2]=-1;
        f[x2+1][y2-2]=-1;
        f[x2+2][y2-1]=-1;
        f[x2+2][y2+1]=-1;
        f[x2+1][y2+2]=-1;
        
        //ans[1][1]=1;
        ans[1][0]=1;
        for(int i=1;i<=x1;i++){
            for(int j=1;j<=t1;j++){
                if(f[i][j]==-1) 
                   { ans[i][j]=0; continue; }
                else 
                   { ans[i][j]=ans[i-1][j]+ans[i][j-1]; }
                //cout<<ans[i][j];
            }
            //cout<<endl;
        }
        cout<<ans[x1][t1];
        return 0;
    }
  • 相关阅读:
    神经网络(2)---neurons and the brain
    P2P system:How Chord tackles failures
    如何成为更好的自己
    P2P system: Chord
    P2P system: FastTrack and BitTorrent
    P2P system: GNUTELLA
    P2P system: Napster
    P2P system: Introduction
    幸福公开课(2)
    MTV与MVC 多对多表的创建方式 前后端传输数据编码格式 ajax 批量插入数据 自定义分页器
  • 原文地址:https://www.cnblogs.com/wuhu-JJJ/p/11237798.html
Copyright © 2020-2023  润新知