From 6067adf5c31343d36b25167d7055c831979c7166 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Mon, 6 Feb 2023 17:22:53 +0800 Subject: [PATCH] =?UTF-8?q?P5505=20[JSOI2011]=E5=88=86=E7=89=B9=E4=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/101578696 --- Luogu/P5505/P5505.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Luogu/P5505/P5505.cpp diff --git a/Luogu/P5505/P5505.cpp b/Luogu/P5505/P5505.cpp new file mode 100644 index 00000000..c448136a --- /dev/null +++ b/Luogu/P5505/P5505.cpp @@ -0,0 +1,53 @@ +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 2005; +const int mod = 1e9 + 7; + +int n, m, a[N], c[N][N], f[N], ans; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + c[0][0] = 1; + + for (int i = 1; i < N; ++i) { + c[i][0] = 1; + + for (int j = 1; j <= i; ++j) { + c[i][j] = (static_cast(c[i - 1][j - 1]) + c[i - 1][j]) % mod; + } + } + + cin >> n >> m; + + for (int i = 1; i <= m; i++) { + cin >> a[i]; + } + + for (int i = 0; i < n; i++) { + f[i] = 1; + + for (int j = 1; j <= m; j++) { + f[i] = static_cast(f[i]) * c[n - i + a[j] - 1][n - i - 1] % mod; + } + + f[i] = static_cast(f[i]) * c[n][i] % mod; + } + + for (int i = 0; i < n; i++) { + if (i % 2 == 0) { + ans = (static_cast(ans) + f[i]) % mod; + } else { + ans = (static_cast(ans) - f[i] + mod) % mod; + } + } + + cout << ans << endl; + + return 0; +}