题解:CF2120D Matrix game

· · 题解

赛时唐了,看到组合数不会算了。

先考虑 n。

根据鸽笼原理,每列中至少应有一种数出现 a 次。

那么很显然,n 最少为 k\times(a-1)+1。

再考虑 m。

设 x 为每列中能出现的不同方案数,很显然 x={n\choose a}\times k。这个组合是可以暴力算的。

根据鸽笼原理,这个矩阵中最少要有一种方案出现了 b 次,那么 m=x\times (b-1)+1。

code:

#include<bits/stdc++.h>
using namespace std;
#define int long long

const int mod=1e9+7;
int a,b,k;
int n,m; 

int fp(int a,int b){
    int ans=1;
    while(b){
        if(b&1) (ans*=a)%=mod;
        (a*=a)%=mod;
        b>>=1;
    }
    return ans;
} 
int inv(int x){
    return fp(x,mod-2)%mod;
}

int calc(int x,int y){
    int res=1;
    for(int i=1;i<=y;i++) (res*=inv(i)*((n-i+1+mod))%mod)%=mod;
    return res;
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int T;cin>>T;while(T--){
        cin>>a>>b>>k;
        n=(a-1)*k+1;n%=mod;
        m=calc(n,a);m=m*k%mod*(b-1)%mod+1;m%=mod;
        cout<<n<<' '<<m<<endl;
    }
    return 0;
}