From 7f893ac0ffafeeabcd68da46d8164f2344d221b5 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Tue, 6 Sep 2022 16:54:42 +0800 Subject: [PATCH] =?UTF-8?q?P2051=20[AHOI2009]=20=E4=B8=AD=E5=9B=BD?= =?UTF-8?q?=E8=B1=A1=E6=A3=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/85999692 --- Luogu/P2051/P2051.cpp | 87 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 Luogu/P2051/P2051.cpp diff --git a/Luogu/P2051/P2051.cpp b/Luogu/P2051/P2051.cpp new file mode 100644 index 00000000..11cc1fd7 --- /dev/null +++ b/Luogu/P2051/P2051.cpp @@ -0,0 +1,87 @@ +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 105; +const int mod = 9999973; + +int n, m; +long long f[N][N][N]{1}, ans; + +long long C(long long x) { + return x * (x - 1) / 2; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m; + + for (int i = 1; i <= n; i++) { + // 不增加炮 + for (int j = 0; j <= m; j++) { + for (int k = 0; j + k <= m; k++) { + f[i][j][k] = f[i - 1][j][k]; + } + } + + // 增加 1 个炮 + // + // 从 1 个炮增加到 2 个炮 + for (int j = 0; j <= m; j++) { + for (int k = 1; j + k <= m; k++) { + f[i][j][k] = (f[i][j][k] + f[i - 1][j + 1][k - 1] * (j + 1) % mod) % mod; + } + } + + // 增加 1 个炮 + // + // 从 0 个炮增加到 1 个炮 + for (int j = 1; j <= m; j++) { + for (int k = 0; j + k <= m; k++) { + f[i][j][k] = (f[i][j][k] + f[i - 1][j - 1][k] * (m - j - k + 1) % mod) % mod; + } + } + + // 增加 2 个炮 + // + // 一列从 0 个炮增加到 1 个炮 + // 一列从 1 个炮增加到 2 个炮 + for (int j = 0; j <= m; j++) { + for (int k = 1; j + k <= m; k++) { + f[i][j][k] = (f[i][j][k] + f[i - 1][j][k - 1] * j * (m - j - k + 1) % mod) % mod; + } + } + + // 增加 2 个炮 + // + // 两列从 0 个炮增加到 1 个炮 + for (int j = 2; j <= m; j++) { + for (int k = 0; j + k <= m; k++) { + f[i][j][k] = (f[i][j][k] + f[i - 1][j - 2][k] * C(m - j - k + 2) % mod) % mod; + } + } + + // 增加 2 个炮 + // + // 两列从 1 个炮增加到 2 个炮 + for (int j = 0; j <= m; j++) { + for (int k = 2; j + k <= m; k++) { + f[i][j][k] = (f[i][j][k] + f[i - 1][j + 2][k - 2] * C(j + 2) % mod) % mod; + } + } + } + + for (int i = 0; i <= m; i++) { + for (int j = 0; i + j <= m; j++) { + ans = (ans + f[n][i][j]) % mod; + } + } + + cout << ans << endl; + + return 0; +}