牛客网暑期ACM多校训练营(第一场) A Monotonic Matrix【LGV】

https://www.nowcoder.com/acm/contest/139/A

将0 1 2填入矩阵,使得 a [ i ] [ j ] >= a [ i 1 ] [ j ] && a [ i ] [ j ] >= a [ i ] [ j 1 ]
抽象:将0 1的分割线视作一条路径,将1 2的分割线视作一条路径,问题可以转换成LGV问题。

这里写图片描述

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define clr(x,y) memset(x,y,sizeof x)
const int maxn=2e3+50;
const ll p=1e9+7;
ll c[maxn][maxn];
int main()
{
    int n,m;clr(c,0);
    for(int i=1;i<maxn;i++){
        c[i][0]=1;c[i][i]=1;
        for(int j=1;j<maxn;j++){
            if(!c[i][j])
            c[i][j]=(c[i-1][j]+c[i-1][j-1]+p)%p;

        }
    }
    //cout<<c[2][2]<<endl;
    while(scanf("%d %d",&n,&m)!=EOF){
        ll ans=0;
        ans+=c[n+m][n]*c[n+m][n]%p-c[n+m][m-1]*c[n+m][n-1]%p;
        ans+=p;
        ans%=p;
        printf("%lld\n",ans);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/irish_moonshine/article/details/81180196