Cattleya number of applications - go (x, y)

(0,0) to (x, y) the number of different paths, only a single-step in the positive direction xy, y = x and can not exceed
if it does not reach the (x, y) is output -1.

Input formats:

Row of two integers x, y, are separated by spaces. Input ensure x = y. | X | ≤2000, | y | ≤2000

Output formats:

Since the line an integer number may be larger, you only need to output its result of the modulo 1e9 + 7 to
if it can not reach the (x, y) is output -1.

Sample input:

1 1

Sample output:

1

Cattleya number of applications

#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
using namespace std;
const int mod=1e9+7;
const int maxn=4100;
int c[maxn][maxn];

int main(){
    int x,y;
    cin >> x >> y;
    
    if(x<0 || y<0)  //只能沿正方向运动
        cout << -1 << endl;
    else{
        for(int i=0; i<=4000; i++) //初始
            c[i][0] = c[i][i] = 1;
        for(int i=2; i<=4000; i++) //组合数的运算
            for(int j=1; j<=i/2; j++){ //算一半即可
                c[i][j] = (c[i-1][j] + c[i-1][j-1])%mod;
                c[i][i-j] = c[i][j];
            }
        cout << (c[2*x][x]-c[2*x][x-1]+mod)%mod << endl;
    }
    return 0;
}


Published 62 original articles · won praise 0 · Views 1757

Guess you like

Origin blog.csdn.net/jhckii/article/details/104345137