#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9, MOD = 1e9 + 7;
int main() {
int N, L;
cin >> N >> L;
vector<int> A(N + 1);
for (int i = 1; i <= N; i++)
cin >> A[i];
sort(A.begin() + 1, A.end());
A.push_back(INF);
if (N == 1) {
cout << 1 << '\n';
return 0;
}
vector<vector<vector<array<long long, 3>>>> dp(N + 1, vector<vector<array<long long, 3>>>(N + 1, vector<array<long long, 3>>(L + 1)));
dp[0][0][0][0] = 1;
for (int i = 1; i <= N; i++)
for (int j = 1; j <= i; j++)
for (int k = 0; k <= L; k++)
for (int m = 0; m <= 2; m++)
if (((2 * j - m) * (A[i + 1] - A[i])) <= k && i + j + 1 - m <= N)
dp[i][j][k][m] = ((dp[i - 1][j - 1][k - ((2 * j - m) * (A[i + 1] - A[i]))][m]) +(m == 0 ? 0 : (3 - m) * dp[i - 1][j - 1][k - ((2 * j - m) * (A[i + 1] - A[i]))][m - 1]) + ((2 * j - m) * dp[i - 1][j][k - ((2 * j - m) * (A[i + 1] - A[i]))][m]) + (m == 0 ? 0 : (m == 1 ? 2 * j * dp[i - 1][j][k - ((2 * j - m) * (A[i + 1] - A[i]))][m - 1] : (i == N ? dp[i - 1][j][k - ((2 * j - m) * (A[i + 1] - A[i]))][m - 1] : (j - 1) * dp[i - 1][j][k - ((2 * j - m) * (A[i + 1] - A[i]))][m - 1]))) + (m == 0 ? j * (j + 1) * dp[i - 1][j + 1][k - ((2 * j - m) * (A[i + 1] - A[i]))][m] : (m == 1 ? j * j * dp[i - 1][j + 1][k - ((2 * j - m) * (A[i + 1] - A[i]))][m] : (i == N ? dp[i - 1][j + 1][k - ((2 * j - m) * (A[i + 1] - A[i]))][m] : j * (j - 1) * dp[i - 1][j + 1][k - ((2 * j - m) * (A[i + 1] - A[i]))][m])))) % MOD;
long long ans = 0;
for (int k = 0; k <= L; k++)
ans += dp[N][1][k][2];
cout << ans % MOD << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
2260 KB |
Output is correct |
6 |
Correct |
1 ms |
2004 KB |
Output is correct |
7 |
Correct |
0 ms |
596 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
2132 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
852 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
852 KB |
Output is correct |
5 |
Correct |
1 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
2260 KB |
Output is correct |
6 |
Correct |
1 ms |
2004 KB |
Output is correct |
7 |
Correct |
0 ms |
596 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
2132 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
0 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
852 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
852 KB |
Output is correct |
15 |
Correct |
1 ms |
852 KB |
Output is correct |
16 |
Correct |
1 ms |
724 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
1 ms |
724 KB |
Output is correct |
21 |
Correct |
2 ms |
1876 KB |
Output is correct |
22 |
Correct |
77 ms |
122644 KB |
Output is correct |
23 |
Correct |
133 ms |
238372 KB |
Output is correct |
24 |
Correct |
113 ms |
180368 KB |
Output is correct |
25 |
Correct |
158 ms |
241228 KB |
Output is correct |
26 |
Correct |
118 ms |
205264 KB |
Output is correct |
27 |
Correct |
37 ms |
59860 KB |
Output is correct |
28 |
Correct |
45 ms |
73364 KB |
Output is correct |
29 |
Correct |
86 ms |
139236 KB |
Output is correct |
30 |
Correct |
151 ms |
242592 KB |
Output is correct |