#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 105;
int n, m, a[N], f[2][N][N * 10][2][2];
void add(int &x, int y) {
x += y; if (x >= mod) x -= mod;
}
int main() {
ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= n; ++i) cin >> a[i];
if (n == 1) {
cout << "1\n"; return 0;
}
sort(a + 1, a + 1 + n);
f[0][0][0][0][0] = 1;
for (int i = 0; i < n; ++i) {
bool t = i & 1;
memset(f[t ^ 1], 0, sizeof f[t ^ 1]);
for (int j = 0; j <= i; ++j) for (int k = 0; k <= m; ++k) {
for (int l = 0; l <= 1; ++l) for (int r = 0; r <= 1; ++r) {
if (!f[t][j][k][l][r]) continue;
//cout << i << ' ' << j << ' ' << k << ' ' << l << ' ' << r << ' ' << f[t][j][k][l][r] << '\n';
int nk = k + (2 * j - l - r) * (a[i + 1] - a[i]);
if (nk > m || j < l + r) continue;
// add l, r
if (!l) {
// make new component
add(f[t ^ 1][j + 1][nk][1][r], f[t][j][k][l][r]);
// add to start of one component
add(f[t ^ 1][j][nk][1][r], f[t][j][k][l][r]);
}
if (!r) {
// make new component
add(f[t ^ 1][j + 1][nk][l][1], f[t][j][k][l][r]);
// add to end of one component
add(f[t ^ 1][j][nk][l][1], f[t][j][k][l][r]);
}
// add new component != l && r
add(f[t ^ 1][j + 1][nk][l][r], 1LL * f[t][j][k][l][r] * (j - l - r + 1) % mod);
// add end to l || add start to r
if (l) add(f[t ^ 1][j][nk][l][r], f[t][j][k][l][r]);
if (r) add(f[t ^ 1][j][nk][l][r], f[t][j][k][l][r]);
// add end || start to components != l && r
add(f[t ^ 1][j][nk][l][r], 2LL * f[t][j][k][l][r] * (j - l - r) % mod);
// connect 2 components
if (j) add(f[t ^ 1][j - 1][nk][l][r], 1LL * f[t][j][k][l][r] * (j - 1) % mod);
}
}
}
int res = 0;
for (int i = 0; i <= m; ++i) add(res, f[n & 1][1][i][1][1]);
cout << res << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5620 KB |
Output is correct |
2 |
Correct |
0 ms |
5620 KB |
Output is correct |
3 |
Correct |
0 ms |
5620 KB |
Output is correct |
4 |
Correct |
3 ms |
5620 KB |
Output is correct |
5 |
Correct |
0 ms |
5620 KB |
Output is correct |
6 |
Correct |
3 ms |
5620 KB |
Output is correct |
7 |
Correct |
0 ms |
5620 KB |
Output is correct |
8 |
Correct |
0 ms |
5620 KB |
Output is correct |
9 |
Correct |
3 ms |
5620 KB |
Output is correct |
10 |
Correct |
3 ms |
5620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5620 KB |
Output is correct |
2 |
Correct |
3 ms |
5620 KB |
Output is correct |
3 |
Correct |
3 ms |
5620 KB |
Output is correct |
4 |
Correct |
0 ms |
5620 KB |
Output is correct |
5 |
Correct |
0 ms |
5620 KB |
Output is correct |
6 |
Correct |
3 ms |
5620 KB |
Output is correct |
7 |
Correct |
3 ms |
5620 KB |
Output is correct |
8 |
Correct |
0 ms |
5620 KB |
Output is correct |
9 |
Correct |
0 ms |
5620 KB |
Output is correct |
10 |
Correct |
0 ms |
5620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5620 KB |
Output is correct |
2 |
Correct |
0 ms |
5620 KB |
Output is correct |
3 |
Correct |
0 ms |
5620 KB |
Output is correct |
4 |
Correct |
3 ms |
5620 KB |
Output is correct |
5 |
Correct |
0 ms |
5620 KB |
Output is correct |
6 |
Correct |
3 ms |
5620 KB |
Output is correct |
7 |
Correct |
0 ms |
5620 KB |
Output is correct |
8 |
Correct |
0 ms |
5620 KB |
Output is correct |
9 |
Correct |
3 ms |
5620 KB |
Output is correct |
10 |
Correct |
3 ms |
5620 KB |
Output is correct |
11 |
Correct |
3 ms |
5620 KB |
Output is correct |
12 |
Correct |
3 ms |
5620 KB |
Output is correct |
13 |
Correct |
3 ms |
5620 KB |
Output is correct |
14 |
Correct |
0 ms |
5620 KB |
Output is correct |
15 |
Correct |
0 ms |
5620 KB |
Output is correct |
16 |
Correct |
3 ms |
5620 KB |
Output is correct |
17 |
Correct |
3 ms |
5620 KB |
Output is correct |
18 |
Correct |
0 ms |
5620 KB |
Output is correct |
19 |
Correct |
0 ms |
5620 KB |
Output is correct |
20 |
Correct |
0 ms |
5620 KB |
Output is correct |
21 |
Correct |
6 ms |
5620 KB |
Output is correct |
22 |
Correct |
159 ms |
5620 KB |
Output is correct |
23 |
Correct |
89 ms |
5620 KB |
Output is correct |
24 |
Correct |
86 ms |
5620 KB |
Output is correct |
25 |
Correct |
93 ms |
5620 KB |
Output is correct |
26 |
Correct |
79 ms |
5620 KB |
Output is correct |
27 |
Correct |
46 ms |
5620 KB |
Output is correct |
28 |
Correct |
59 ms |
5620 KB |
Output is correct |
29 |
Correct |
96 ms |
5620 KB |
Output is correct |
30 |
Correct |
76 ms |
5620 KB |
Output is correct |