NC13884. Paint Box
描述
输入描述
The first line of the input contains integer T(1≤T≤100) -the number of the test casesFor each case: there will be one line, which contains three integers n,m,k(1≤n,m≤109 1≤k≤106, k≤n,m).
输出描述
For each test case, you need print an integer means the number of ways of different coloring methods modulo 109+7.
示例1
输入:
2 3 2 2 3 2 1
输出:
2 0
说明:
In the first example we have two ways:C++(clang++11) 解法, 执行用时: 297ms, 内存消耗: 376K, 提交时间: 2021-02-15 11:33:23
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll mod=1e9+7; ll fast(ll a,ll b) { ll ans=1; a%=mod; while(b) { if(b&1) ans=(ans*a)%mod; a=(a*a)%mod; b>>=1; } return ans; } ll C(ll n,ll r) { if(n<r) return 0; if(n-r<r) r=n-r; ll a=1,b=1; for(int i=0;i<r;i++) a=(a*(n-i))%mod,b=(b*(i+1))%mod; return a*fast(b,mod-2)%mod; } int main() { int t; scanf("%d",&t); while(t--) { ll n,m,k,i,res=1,ans=0; scanf("%lld %lld %lld",&n,&m,&k); for(i=k;i>=1;i--) { ans=(ans+i*fast(i-1,n-1)%mod*res%mod+mod)%mod; res=-1*res*i%mod*fast(k-i+1,mod-2)%mod; } ans=(ans*C(m,k))%mod; printf("%lld\n",ans); } return 0; }