[ARC058B]Iroha and a Grid

壹、题目描述 ¶

传送门 to Luogu.

贰、题解 ¶

唯一限制条件:当 \(i\le A\) 时,\(j\le B\). 问方案数。

想到一种方案,我们可以用图上的方法来求:

简而言之,我们枚举竖着走了 \(N-A-2\) 步之后,横着走了多少步,但是必须保证横着走的步数大于等于 \(B\),然后把两种方案乘起来即可。

叁、参考代码 ¶

#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;

#define NDUBUG
#include<cassert>

namespace Elaina{
    #define rep(i, l, r) for(int i=(l), i##_end_=(r); i<=i##_end_; ++i)
    #define drep(i, l, r) for(int i=(l), i##_end_=(r); i>=i##_end_; --i)
    #define fi first
    #define se second
    #define mp(a, b) make_pair(a, b)
    #define Endl putchar('\n')
    #define mmset(a, b) memset(a, b, sizeof a)
    // #define int long long
    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair<int, int> pii;
    typedef pair<ll, ll> pll;
    template<class T>inline T fab(T x){ return x<0? -x: x; }
    template<class T>inline void getmin(T& x, const T rhs){ x=min(x, rhs); }
    template<class T>inline void getmax(T& x, const T rhs){ x=max(x, rhs); }
    template<class T>inline T readin(T x){
        x=0; int f=0; char c;
        while((c=getchar())<'0' || '9'<c) if(c=='-') f=1;
        for(x=(c^48); '0'<=(c=getchar()) && c<='9'; x=(x<<1)+(x<<3)+(c^48));
        return f? -x: x;
    }
    template<class T>inline void writc(T x, char s='\n'){
        static int fwri_sta[1005], fwri_ed=0;
        if(x<0) putchar('-'), x=-x;
        do fwri_sta[++fwri_ed]=x%10, x/=10; while(x);
        while(putchar(fwri_sta[fwri_ed--]^48), fwri_ed);
        putchar(s);
    }
}
using namespace Elaina;

const int maxn=1e5;
const int mod=1e9+7;

inline int qkpow(int a, int n){
    int ret=1;
    for(; n>0; n>>=1, a=1ll*a*a%mod)
        if(n&1) ret=1ll*ret*a%mod;
    return ret;
}

int fac[maxn*2+5], finv[maxn*2+5];
inline void prelude(){
    fac[0]=1;
    for(int i=1; i<=maxn*2; ++i)
        fac[i]=1ll*fac[i-1]*i%mod;
    finv[maxn*2]=qkpow(fac[maxn*2], mod-2);
    for(int i=maxn*2-1; i>=1; --i)
        finv[i]=1ll*finv[i+1]*(i+1)%mod;
    finv[0]=1;
}

inline int C(int n, int m){
    if(n<m) return 0;
    return 1ll*fac[n]*finv[m]%mod*finv[n-m]%mod;
}

int n, m, a, b, ans;

signed main(){
    prelude();
    n=readin(1), m=readin(1), a=readin(1), b=readin(1);
    for(int i=b+1; i<=m; ++i){
        int fron=C((n-a-1)+(i-1), i-1);
        int step=a-1+m-i;
        int lst=C(step, a-1);
        ans=(ans+1ll*fron*lst%mod)%mod;
    }
    writc(ans);
    return 0;
}
posted @ 2021-07-28 21:33  Arextre  阅读(64)  评论(0编辑  收藏  举报