UVA 11806 组合数学+容斥
UVA: https://vjudge.net/problem/UVA-11806
AC代码
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define fi first #define se second #define all(a) (a).begin(), (a).end() #define fillchar(a, x) memset(a, x, sizeof(a)) #define huan printf("\n") #define debug(a,b) cout<<a<<" "<<b<<" "<<endl #define ffread(a) fastIO::read(a) using namespace std; typedef long long ll; typedef pair<int,int> pii; //const int maxn=1e4+10; const ll mod=1e6+7; const int maxn = 1010; int C[maxn][maxn]; int n, m, k; void init() { C[0][0] = 1; for (int i = 1; i < maxn; i++) { C[i][0] = 1; for (int j = 1; j <= i; j++) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod; } } int main() { int t,kase=1; init(); scanf("%d",&t); while(t--) { scanf("%d%d%d",&m,&n,&k); int ans=C[n*m][k]; ans=(ans-2*C[(m-1)*n][k]%mod+mod)%mod; ans=(ans-2*C[(n-1)*m][k]%mod+mod)%mod; ans=(ans+4*C[(n-1)*(m-1)][k])%mod; ans=(ans+C[(n-2)*m][k])%mod; ans=(ans+C[(m-2)*n][k])%mod; ans=(ans-2*C[(n-2)*(m-1)][k]%mod+mod)%mod; ans=(ans-2*C[(m-2)*(n-1)][k]%mod+mod)%mod; ans=(ans+C[(m-2)*(n-2)][k])%mod; printf("Case %d: %d\n",kase++,ans); } }