이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
constexpr int NMAX = 2005;
constexpr int MOD = 1e9 + 7;
int N, M;
int Contor[NMAX];
int CntGrup[NMAX];
void Read () {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> M;
for (int i = 1; i <= 2*N; ++ i )
Contor[i%M + 1] ++;
for (int i = 1; i <= M; ++ i )
CntGrup[i] = CntGrup[i-1] + Contor[i];
}
int pow2[2*NMAX];
int fact[2*NMAX];
int Comb[2*NMAX][2*NMAX];
void Precompute () {
fact[0] = 1;
pow2[0] = 1;
for (int i = 1; i <= 2*N; ++ i ) {
fact[i] = (1LL * fact[i-1] * i) % MOD;
pow2[i] = (1LL * pow2[i-1] * 2) % MOD;
}
Comb[0][0] = 1;
for (int i = 1; i <= 2*N; ++ i ) {
Comb[i][0] = Comb[i][i] = 1;
for (int j = 1; j < i; ++ j )
Comb[i][j] = (1LL * Comb[i-1][j-1] + 1LL * Comb[i-1][j]) % MOD;
}
}
int dp[NMAX][NMAX];
void Solve () {
dp[0][0] = 1;
for (int grup = 0; grup < M; ++ grup ) {
int Total = CntGrup[grup];
for (int j = 0; j <= N && j <= Total; ++ j ) {
int pairs = (Total - j) / 2;
if (2 * pairs + j != Total) continue;
int pos_new_jum = N - pairs - j;
for (int complete = 0; complete <= j && complete <= Contor[grup+1]; ++ complete ) {
int new_jum = Contor[grup+1] - complete;
if (new_jum > pos_new_jum) continue;
int coef = 1LL * Comb[pos_new_jum][new_jum] * pow2[new_jum] % MOD;
coef = (1LL * coef * Comb[j][complete]) % MOD;
coef = (1LL * coef * fact[Contor[grup+1]]) % MOD;
dp[grup+1][j - complete + new_jum] = (dp[grup+1][j - complete + new_jum] + 1LL * coef * dp[grup][j] % MOD) % MOD;
}
}
}
cout << dp[M][0] << '\n';
}
int main()
{
Read();
Precompute();
Solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |