#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 105, L = 1005, MD = 1e9 + 7;
void add(int &a, int b) {
if ((a += b) >= MD) {
a -= MD;
}
}
int n, l;
int a[N], dp[N][N][L][3];
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> l;
if (n == 1) {
cout << 1;
exit(0);
}
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
a[n + 1] = 10000;
dp[0][0][0][0] = 1;
sort(a + 1, a + n + 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 < 3; ++m) {
int dif = (a[i + 1] - a[i]) * (2 * j - m);
int &res = dp[i][j][k][m];
if (dif <= k && i + j + 1 - m <= n) {
add(res, dp[i - 1][j - 1][k - dif][m]);
add(res, (long long) (2 * j - m) * dp[i - 1][j][k - dif][m] % MD);
if (m > 0) {
add(res, (long long) (3 - m) * dp[i - 1][j - 1][k - dif][m - 1] % MD);
if (m == 1) {
add(res, 2LL * j * dp[i - 1][j][k - dif][m - 1] % MD);
} else {
if (i == n) {
if (j == 1) {
add(res, dp[i - 1][j][k - dif][m - 1]);
}
} else {
add(res, (long long) (j - 1) * dp[i - 1][j][k - dif][m - 1] % MD);
}
}
}
if (m == 2) {
if (i == n) {
add(res, dp[i - 1][j + 1][k - dif][m]);
} else {
add(res, (long long) j * (j - 1) * dp[i - 1][j + 1][k - dif][m] % MD);
}
} else if (m == 1) {
add(res, (long long) j * j * dp[i - 1][j + 1][k - dif][m] % MD);
} else {
add(res, (long long) j * (j + 1) * dp[i - 1][j + 1][k - dif][m] % MD);
}
}
}
}
}
}
int res = 0;
for (int k = 0; k <= l; ++k) {
add(res, dp[n][1][k][2]);
}
cout << res;
return 0;
}
// Thanks Usaco!!!
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
0 ms |
604 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
2 ms |
2140 KB |
Output is correct |
22 |
Correct |
50 ms |
18924 KB |
Output is correct |
23 |
Correct |
71 ms |
25940 KB |
Output is correct |
24 |
Correct |
61 ms |
27888 KB |
Output is correct |
25 |
Correct |
74 ms |
27476 KB |
Output is correct |
26 |
Correct |
63 ms |
26196 KB |
Output is correct |
27 |
Correct |
28 ms |
17076 KB |
Output is correct |
28 |
Correct |
30 ms |
18780 KB |
Output is correct |
29 |
Correct |
62 ms |
25892 KB |
Output is correct |
30 |
Correct |
71 ms |
27476 KB |
Output is correct |