K L2-3 新旷野地带
题目地址;
基本思路:
比较简单的组合问题,我们枚举放个极巨化坑,那么每次我们从行里选行,然后每次多选定了一列,接下来能选择的列数就会减少一,也就是能得到也就是,枚举 然后求个逆元算答案就好了。
参考代码:
#pragma GCC optimize(2) #pragma GCC optimize(3) #include <bits/stdc++.h> using namespace std; #define IO std::ios::sync_with_stdio(false) #define int long long #define rep(i, l, r) for (int i = l; i <= r; i++) #define per(i, l, r) for (int i = l; i >= r; i--) #define mset(s, _) memset(s, _, sizeof(s)) #define pb push_back #define pii pair <int, int> #define mp(a, b) make_pair(a, b) #define INF 0x3f3f3f3f inline int read() { int x = 0, neg = 1; char op = getchar(); while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); } while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); } return neg * x; } inline void print(int x) { if (x < 0) { putchar('-'); x = -x; } if (x >= 10) print(x / 10); putchar(x % 10 + '0'); } const int maxn = 1e6 + 10; int fact[maxn]; inline int qsm(int x,int n,int mod) { int res = 1; while (n > 0) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } inline int mod_comb(int n,int k,int mod) { if(n == k || k == 0) return 1; return fact[n] * qsm(fact[k] * fact[n - k] % mod, mod - 2, mod) % mod; } const int mod = 1e9 + 7; int n,m,k; signed main() { IO; fact[0] = 0, fact[1] = 1; for (int i = 2; i < maxn; i++) fact[i] = fact[i - 1] * i % mod; cin >> n >> m >> k; int ans = 0; rep(i,1,k){ if(i > n || i > m) break; int tmp = mod_comb(n,i,mod) * fact[m] % mod; if( m - i > 0 ) tmp *= qsm(fact[m - i],mod - 2,mod) % mod; tmp %= mod; ans = (ans + tmp) % mod; } cout << ans << '\n'; return 0; }