zoukankan      html  css  js  c++  java
  • luogu P1002 过河卒

    题目描述

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

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

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

    输入输出格式

    输入格式:

    一行四个数据,分别表示B点坐标和马的坐标。

    输出格式:

    一个数据,表示所有的路径条数。

    输入输出样例

    输入样例#1:
    6 6 3 3
    
    输出样例#1:
    6
    

    说明

    结果可能很大!

    最基础的dp

     1 #include<iostream>
     2 using namespace std;
     3 const int N=120;
     4 int t=10;
     5 long long dp[N][N],b[N][N],hor[N][N],n,m,x,y;
     6 int main()
     7 {
     8     cin>>n>>m>>x>>y;
     9     hor[x+t][y+t]=1;
    10     hor[x-2+t][y+1+t]=1;
    11     hor[x+2+t][y+1+t]=1;
    12     hor[x-1+t][y+2+t]=1;
    13     hor[x+1+t][y+2+t]=1;
    14     hor[x-2+t][y-1+t]=1;
    15     hor[x+2+t][y-1+t]=1;
    16     hor[x-1+t][y-2+t]=1;
    17     hor[x+1+t][y-2+t]=1;
    18     dp[t][t-1]=1;
    19     for(int i=t;i<=n+t;i++)
    20     {
    21         for(int j=t;j<=m+t;j++)
    22         {
    23             if(hor[i][j]!=1)
    24                 dp[i][j]=dp[i-1][j]+dp[i][j-1];    
    25         }
    26     }
    27     cout<<dp[t+n][t+m];
    28     return 0;
    29 }
  • 相关阅读:
    ubuntu下安装maven
    159.Longest Substring with At Most Two Distinct Characters
    156.Binary Tree Upside Down
    155.Min Stack
    154.Find Minimum in Rotated Sorted Array II
    153.Find Minimum in Rotated Sorted Array
    152.Maximum Product Subarray
    151.Reverse Words in a String
    150.Evaluate Reverse Polish Notation
    149.Max Points on a Line
  • 原文地址:https://www.cnblogs.com/sssy/p/6857483.html
Copyright © 2011-2022 走看看