标签:lov family find bsp AC while long 编号 ble
1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 #define LL long long 5 using namespace std; 6 const int N=2e3+5; 7 const int mod=1e9+7; 8 int n,m,fac[N*N],inv[N*N],f[N][N]; 9 int read() 10 { 11 int x=0,f=1;char c=getchar(); 12 while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1;c=getchar();} 13 while(c>=‘0‘&&c<=‘9‘){x=x*10+c-‘0‘;c=getchar();} 14 return x*f; 15 } 16 void Mod(int& a,int b){a+=b;if(a>=mod)a-=mod;} 17 int power(int a,int b) 18 { 19 int ans=1; 20 while(b) 21 { 22 if(b&1)ans=1ll*ans*a%mod; 23 a=1ll*a*a%mod;b>>=1; 24 } 25 return ans; 26 } 27 int C(int n,int m){return 1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;} 28 int main() 29 { 30 n=read();m=read(); 31 if(m==1){printf("1");return 0;} 32 fac[0]=1; 33 for(int i=1;i<=n*m;i++)fac[i]=1ll*fac[i-1]*i%mod; 34 inv[n*m]=power(fac[n*m],mod-2); 35 for(int i=n*m;i>=1;i--)inv[i-1]=1ll*inv[i]*i%mod; 36 f[0][0]=1; 37 for(int i=1;i<=n;i++) 38 for(int j=0;j<=i;j++) 39 { 40 f[i][j]=f[i-1][j]; 41 if(!j)continue; 42 Mod(f[i][j],1ll*f[i][j-1]*(n-j+1)%mod*C(n-i+(n-j+1)*(m-1)-1,m-2)%mod); 43 } 44 printf("%d",f[n][n]); 45 return 0; 46 }
标签:lov family find bsp AC while long 编号 ble
原文地址:https://www.cnblogs.com/zsnuo/p/8898199.html