[1002] Guohe Cu Los Valley

Title Description

There is a point on the board Guohe Cu AA, BB needs to go to the target point. Death walking rules: can be down, or right. CC points on the board at the same time there is the other side of a horse, the point where the horse jumps and step up all the points called control points other horses. So called "horse stopped Guohe Cu."

Chessboard coordinate representation, AA point (0, 0) (0,0), BB point (n, m) (n, m) (nn, mm is an integer of not more than 2020), the same positional coordinates of the horse is the need to out.

Now we ask you to calculate the number of paths to reach the BB point of death from AA point, assuming that the position of the horse is stationary, not a soldier walking horse go step by step.

Input and output formats

Input format:
a row of four data, respectively, the coordinates of point coordinates BB and horses.

Output format:
a data representing the number of all paths.

Sample input and output

Input Sample # 1: Copy
6633
Output Sample # 1: Copy
6
Description

The results can be significant!

Solution: wow I actually have not written this question ...... ordinary two-dimensional DP friends, but have to consider negative circumstances, the collective displacement 1. The initial settings should be ans [1] [0] = 1 instead ans [1] [1] = 1; check for a long time! ! !

Code:

#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 << years [i] [j]; 
        }
         // cout << endl; 
    } 
    Cout << years [x1] [t1];
    return  0 ; 
}

 

Guess you like

Origin www.cnblogs.com/wuhu-JJJ/p/11237798.html