From fb37785085b24143419c02d6a4342e809f64d200 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Fri, 9 Dec 2022 20:58:12 +0800 Subject: [PATCH] =?UTF-8?q?P4609=20[FJOI2016]=E5=BB=BA=E7=AD=91=E5=B8=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/96923331 --- Luogu/P4609/P4609.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Luogu/P4609/P4609.cpp diff --git a/Luogu/P4609/P4609.cpp b/Luogu/P4609/P4609.cpp new file mode 100644 index 00000000..7d3e93c0 --- /dev/null +++ b/Luogu/P4609/P4609.cpp @@ -0,0 +1,52 @@ +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 5e4 + 5, + M = 205; +const int mod = 1e9 + 7; + +int s[N][M], c[M][M]; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + s[0][0] = s[1][1] = 1; + + for (int i = 2; i < N; i++) { + s[i][1] = static_cast(s[i - 1][1]) * (i - 1) % mod; + } + + for (int i = 2; i < N; i++) { + for (int j = 1; j < M && j <= i; j++) { + s[i][j] = (static_cast(s[i - 1][j - 1]) + static_cast(s[i - 1][j]) * (i - 1)) % mod; + } + } + + for (int i = 0; i < M; i++) { + c[i][0] = c[i][i] = 1; + } + + for (int i = 2; i < M; i++) { + for (int j = 1; j < i; j++) { + c[i][j] = (static_cast(c[i - 1][j]) + c[i - 1][j - 1]) % mod; + } + } + + int t; + + cin >> t; + + while (t--) { + int n, a, b; + + cin >> n >> a >> b; + + cout << static_cast(s[n - 1][a + b - 2]) * c[a + b - 2][a - 1] % mod << endl; + } + + return 0; +}