#include <bits/stdc++.h>
using namespace std;
const int N = 101, L = 1001, MOD = 1e9 + 7;
int a[N], dif[N], dp[N][N][L][3];
int mul(int a, int b) {return 1ll * a * b % MOD;}
void add(int &a, const int &b) {a += b; if (a >= MOD) a -= MOD; return ;}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n, s; cin >> n >> s;
if (n == 1) return cout << 1 << "\n", 0;
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
for (int i = 1; i < n; i++) dif[i] = a[i] - a[i - 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 <= s; k++) {
int x = 2 * j, y = j * (j + 1);
if (k >= x * dif[i]) {
add(dp[i][j][k][0], mul(dp[i - 1][j][k - x * dif[i]][0], x));
add(dp[i][j][k][0], mul(dp[i - 1][j + 1][k - x * dif[i]][0], y));
add(dp[i][j][k][0], dp[i - 1][j - 1][k - x * dif[i]][0]);
}
x--, y -= j;
if (k >= x * dif[i]) {
add(dp[i][j][k][1], mul(dp[i - 1][j][k - x * dif[i]][1], x));
add(dp[i][j][k][1], mul(dp[i - 1][j + 1][k - x * dif[i]][1], y));
add(dp[i][j][k][1], dp[i - 1][j - 1][k - x * dif[i]][1]);
add(dp[i][j][k][1], mul(dp[i - 1][j][k - x * dif[i]][0], 2 * j));
add(dp[i][j][k][1], mul(dp[i - 1][j - 1][k - x * dif[i]][0], 2));
}
x--, y -= j;
if (k >= x * dif[i]) {
add(dp[i][j][k][2], mul(dp[i - 1][j][k - x * dif[i]][2], x));
add(dp[i][j][k][2], mul(dp[i - 1][j + 1][k - x * dif[i]][2], y));
add(dp[i][j][k][2], dp[i - 1][j - 1][k - x * dif[i]][2]);
add(dp[i][j][k][2], mul(dp[i - 1][j][k - x * dif[i]][1], j - 1));
add(dp[i][j][k][2], dp[i - 1][j - 1][k - x * dif[i]][1]);
if (i == n && j == 1) {
add(dp[i][j][k][2], dp[i - 1][j + 1][k - x * dif[i]][2]);
add(dp[i][j][k][2], dp[i - 1][j][k - x * dif[i]][1]);
}
}
}
}
}
int ans = 0;
for (int k = 0; k <= s; k++) add(ans, dp[n][1][k][2]);
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
640 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
768 KB |
Output is correct |
2 |
Correct |
1 ms |
768 KB |
Output is correct |
3 |
Correct |
1 ms |
800 KB |
Output is correct |
4 |
Correct |
1 ms |
768 KB |
Output is correct |
5 |
Correct |
1 ms |
768 KB |
Output is correct |
6 |
Correct |
2 ms |
896 KB |
Output is correct |
7 |
Correct |
1 ms |
768 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
1 ms |
896 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
640 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
2 ms |
768 KB |
Output is correct |
12 |
Correct |
1 ms |
768 KB |
Output is correct |
13 |
Correct |
1 ms |
800 KB |
Output is correct |
14 |
Correct |
1 ms |
768 KB |
Output is correct |
15 |
Correct |
1 ms |
768 KB |
Output is correct |
16 |
Correct |
2 ms |
896 KB |
Output is correct |
17 |
Correct |
1 ms |
768 KB |
Output is correct |
18 |
Correct |
1 ms |
768 KB |
Output is correct |
19 |
Correct |
1 ms |
896 KB |
Output is correct |
20 |
Correct |
1 ms |
768 KB |
Output is correct |
21 |
Correct |
3 ms |
3072 KB |
Output is correct |
22 |
Correct |
116 ms |
36584 KB |
Output is correct |
23 |
Correct |
125 ms |
43640 KB |
Output is correct |
24 |
Correct |
119 ms |
46824 KB |
Output is correct |
25 |
Correct |
129 ms |
43896 KB |
Output is correct |
26 |
Correct |
116 ms |
43004 KB |
Output is correct |
27 |
Correct |
55 ms |
31352 KB |
Output is correct |
28 |
Correct |
70 ms |
34680 KB |
Output is correct |
29 |
Correct |
118 ms |
47480 KB |
Output is correct |
30 |
Correct |
127 ms |
43900 KB |
Output is correct |