#include <bits/stdc++.h>
#define DEBUG false
using namespace std;
const int MAX_N = 105;
const int MAX_L = 1005;
const int MOD = 1e9 + 7;
int A[MAX_N];
long long dp[MAX_N][MAX_N][MAX_L][3];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N, L;
cin >> N >> L;
for(int i = 1; i <= N; i++) {
cin >> A[i];
}
if(N == 1) { // special case
cout << 1;
return 0;
}
sort(A + 1, A + N + 1);
dp[1][1][0][0] = 1;
dp[1][1][0][1] = 2;
for(int i = 1; i < N; i++) {
for(int j = 1; j <= i; j++) {
for(int k = 0; k <= L; k++) {
for(int z = 0; z <= 2; z++) {
int nk = k + (2 * j - z) * (A[i + 1] - A[i]);
if(nk > L) {
continue;
}
if(z < 2) { // add i to end point
dp[i + 1][j][nk][z + 1] += (2 - z) * dp[i][j][k][z]; // add i to the left or right most component to be an end point
dp[i + 1][j][nk][z + 1] %= MOD;
dp[i + 1][j + 1][nk][z + 1] = (2 - z) * dp[i][j][k][z]; // create new component to the left or right most
dp[i + 1][j + 1][nk][z + 1] %= MOD;
}
dp[i + 1][j][nk][z] += (2 * j - z) * dp[i][j][k][z]; // add i to left or right most of some components
dp[i + 1][j][nk][z] %= MOD;
dp[i + 1][j + 1][nk][z] += (j + 1 - z) * dp[i][j][k][z]; // create new component
dp[i + 1][j + 1][nk][z] %= MOD;
dp[i + 1][j - 1][nk][z] += (j - 1) * dp[i][j][k][z]; // merge two components
dp[i + 1][j - 1][nk][z] %= MOD;
}
}
}
}
long long ans = 0;
for(int k = 0; k <= L; k++) {
ans += dp[N][1][k][2];
ans %= MOD;
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
1108 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
852 KB |
Output is correct |
2 |
Correct |
1 ms |
852 KB |
Output is correct |
3 |
Correct |
1 ms |
852 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 |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
852 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
1108 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
852 KB |
Output is correct |
12 |
Correct |
1 ms |
852 KB |
Output is correct |
13 |
Correct |
1 ms |
852 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 |
980 KB |
Output is correct |
17 |
Correct |
1 ms |
852 KB |
Output is correct |
18 |
Correct |
1 ms |
852 KB |
Output is correct |
19 |
Correct |
1 ms |
980 KB |
Output is correct |
20 |
Correct |
1 ms |
852 KB |
Output is correct |
21 |
Correct |
2 ms |
3540 KB |
Output is correct |
22 |
Correct |
82 ms |
69020 KB |
Output is correct |
23 |
Correct |
111 ms |
80892 KB |
Output is correct |
24 |
Correct |
106 ms |
79056 KB |
Output is correct |
25 |
Correct |
107 ms |
81616 KB |
Output is correct |
26 |
Correct |
98 ms |
76452 KB |
Output is correct |
27 |
Correct |
44 ms |
43212 KB |
Output is correct |
28 |
Correct |
53 ms |
49932 KB |
Output is correct |
29 |
Correct |
92 ms |
76160 KB |
Output is correct |
30 |
Correct |
109 ms |
81888 KB |
Output is correct |