#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define F first
#define S second
#define All(x) (x).begin(),(x).end()
#define len(x) (int)(x).size()
#define pb push_back
#define int long long
const int N = 100 + 7, M = 1000 + 7, P = 1e9 + 7;
int n, l, a[N], dp[N][N][M][3];
int32_t main() {
ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> l;
for (int i = 1; i <= n; i++)
cin >> a[i];
sort(a + 1, a + n + 1);
a[n + 1] = 1e4;
if (n == 1) {
cout << 1 << '\n';
return 0;
}
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++) {
int t = 2 * j * (a[i + 1] - a[i]) - m * (a[i + 1] - a[i]);
if (t > k || i + j + 1 - m > n)
continue;
// j - 1 => j
dp[i][j][k][m] = (dp[i][j][k][m] + dp[i - 1][j - 1][k - t][m]) % P;
if (m)
dp[i][j][k][m] = (dp[i][j][k][m] + (2 - (m - 1)) * dp[i - 1][j - 1][k - t][m - 1]) % P;
// j => j adi
dp[i][j][k][m] = (dp[i][j][k][m] + 1LL * (2 * (j - m) + m) * dp[i - 1][j][k - t][m] % P) % P;
// j => j gooshe
if (m == 1)
dp[i][j][k][m] = (dp[i][j][k][m] + 2 * j * dp[i - 1][j][k - t][0] % P) % P;
else if (m == 2) {
if (i == n) {
if (j == 1)
dp[i][j][k][m] = (dp[i][j][k][m] + dp[i - 1][j][k - t][m - 1]) % P;
}
else
dp[i][j][k][m] = (dp[i][j][k][m] + (j - 1) * dp[i - 1][j][k - t][m - 1] % P) % P;
}
// j + 1 => j
if (m == 2) {
if (i == n) {
if (j == 1)
dp[i][j][k][m] = (dp[i][j][k][m] + dp[i - 1][j + 1][k - t][m]) % P;
}
else
dp[i][j][k][m] = (dp[i][j][k][m] + 1LL * j * (j - 1) % P * dp[i - 1][j + 1][k - t][m] % P) % P;
}
else if (m == 1)
dp[i][j][k][m] = (dp[i][j][k][m] + 1LL * j * j % P * dp[i - 1][j + 1][k - t][m] % P) % P;
else
dp[i][j][k][m] = (dp[i][j][k][m] + 1LL * j * (j + 1) % P * dp[i - 1][j + 1][k - t][m] % P) % P;
}
int ans = 0;
for (int i = 0; i <= l; i++)
ans = (ans + dp[n][1][i][2]) % P;
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
464 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
860 KB |
Output is correct |
6 |
Correct |
1 ms |
860 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
616 KB |
Output is correct |
4 |
Correct |
1 ms |
604 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 |
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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
464 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
860 KB |
Output is correct |
6 |
Correct |
1 ms |
860 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
616 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 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 |
2396 KB |
Output is correct |
22 |
Correct |
62 ms |
35972 KB |
Output is correct |
23 |
Correct |
82 ms |
47700 KB |
Output is correct |
24 |
Correct |
74 ms |
46932 KB |
Output is correct |
25 |
Correct |
89 ms |
50768 KB |
Output is correct |
26 |
Correct |
76 ms |
46164 KB |
Output is correct |
27 |
Correct |
29 ms |
23712 KB |
Output is correct |
28 |
Correct |
35 ms |
26964 KB |
Output is correct |
29 |
Correct |
66 ms |
41212 KB |
Output is correct |
30 |
Correct |
86 ms |
51024 KB |
Output is correct |