From 4f8ad912fa0a90fb8b5d7b5727f504aab85d33fa Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Fri, 25 Nov 2022 16:06:44 +0800 Subject: [PATCH] =?UTF-8?q?P1350=20=E8=BD=A6=E7=9A=84=E6=94=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/95390744 --- Luogu/P1350/P1350.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Luogu/P1350/P1350.cpp diff --git a/Luogu/P1350/P1350.cpp b/Luogu/P1350/P1350.cpp new file mode 100644 index 00000000..bd94dc16 --- /dev/null +++ b/Luogu/P1350/P1350.cpp @@ -0,0 +1,49 @@ +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 2005; +const int mod = 1e5 + 3; + +int a, b, c, d, k, fac[N], inv[N], fac_inv[N], ans; + +inline int C(int n, int m) { + return static_cast(fac[n]) * fac_inv[m] % mod * fac_inv[n - m] % mod; +} + +int f(int n, int m, int k) { + if (k > n || k > m) return 0; + return static_cast(C(n, k)) * C(m, k) % mod * fac[k] % mod; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + fac[0] = 1; + for (int i = 1; i < N; i++) { + fac[i] = static_cast(fac[i - 1]) * i % mod; + } + + inv[0] = inv[1] = 1; + for (int i = 2; i < N; i++) { + inv[i] = static_cast(mod - mod / i) * inv[mod % i] % mod; + } + + fac_inv[0] = fac_inv[1] = 1; + for (int i = 2; i < N; i++) { + fac_inv[i] = static_cast(fac_inv[i - 1]) * inv[i] % mod; + } + + cin >> a >> b >> c >> d >> k; + + for (int i = 0; i <= k; i++) { + ans = (ans + static_cast(f(a, b, i)) * f(a + c - i, d, k - i)) % mod; + } + + cout << ans << endl; + + return 0; +}