#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint MOD = 1e9 + 7;
int N, L;
int A[105];
lint memo[105][105][1005][2][2];
lint dp(int n, int comp, int cost, int l, int r) {
// l = left border
// r = right border
int new_cost = cost + (n > 0 ? A[n] - A[n - 1] : 0) * (2 * comp + l + r);
if (new_cost > L) {
return 0;
}
if (comp < 0) {
return 0;
}
if (n == N - 1) {
return comp == 0 ? 1 : 0;
}
lint &res = memo[n][comp][cost][l][r];
if (res != -1) {
return res;
}
res = 0;
res += dp(n + 1, comp, new_cost, 1, r); // connect A[n] to left border
res += dp(n + 1, comp - 1, new_cost, 1, r) * comp; // merge a component and left border
res += dp(n + 1, comp, new_cost, l, 1); // connect A[n] to right border
res += dp(n + 1, comp - 1, new_cost, l, 1) * comp; // merge a component and right border
res += dp(n + 1, comp + 1, new_cost, l, r); // new component
res += dp(n + 1, comp, new_cost, l, r) * comp * 2; // connect to middle component
res += dp(n + 1, comp - 1, new_cost, l, r) * comp * (comp - 1); // merge two middle component
res %= MOD;
return res;
}
int main() {
memset(memo, -1, sizeof(memo));
cin >> N >> L;
for (int i = 0; i < N; i++) {
cin >> A[i];
}
sort(A, A + N);
cout << dp(0, 0, 0, 0, 0) << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
299 ms |
347280 KB |
Output is correct |
2 |
Correct |
290 ms |
347384 KB |
Output is correct |
3 |
Correct |
299 ms |
347240 KB |
Output is correct |
4 |
Correct |
302 ms |
347276 KB |
Output is correct |
5 |
Correct |
348 ms |
347564 KB |
Output is correct |
6 |
Correct |
365 ms |
347320 KB |
Output is correct |
7 |
Correct |
346 ms |
347332 KB |
Output is correct |
8 |
Correct |
324 ms |
347168 KB |
Output is correct |
9 |
Correct |
341 ms |
347228 KB |
Output is correct |
10 |
Correct |
311 ms |
347244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
299 ms |
347420 KB |
Output is correct |
2 |
Correct |
297 ms |
347292 KB |
Output is correct |
3 |
Correct |
296 ms |
347172 KB |
Output is correct |
4 |
Correct |
299 ms |
347172 KB |
Output is correct |
5 |
Correct |
311 ms |
347472 KB |
Output is correct |
6 |
Correct |
298 ms |
347260 KB |
Output is correct |
7 |
Correct |
294 ms |
347240 KB |
Output is correct |
8 |
Correct |
298 ms |
347300 KB |
Output is correct |
9 |
Correct |
301 ms |
347336 KB |
Output is correct |
10 |
Correct |
303 ms |
347256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
299 ms |
347280 KB |
Output is correct |
2 |
Correct |
290 ms |
347384 KB |
Output is correct |
3 |
Correct |
299 ms |
347240 KB |
Output is correct |
4 |
Correct |
302 ms |
347276 KB |
Output is correct |
5 |
Correct |
348 ms |
347564 KB |
Output is correct |
6 |
Correct |
365 ms |
347320 KB |
Output is correct |
7 |
Correct |
346 ms |
347332 KB |
Output is correct |
8 |
Correct |
324 ms |
347168 KB |
Output is correct |
9 |
Correct |
341 ms |
347228 KB |
Output is correct |
10 |
Correct |
311 ms |
347244 KB |
Output is correct |
11 |
Correct |
299 ms |
347420 KB |
Output is correct |
12 |
Correct |
297 ms |
347292 KB |
Output is correct |
13 |
Correct |
296 ms |
347172 KB |
Output is correct |
14 |
Correct |
299 ms |
347172 KB |
Output is correct |
15 |
Correct |
311 ms |
347472 KB |
Output is correct |
16 |
Correct |
298 ms |
347260 KB |
Output is correct |
17 |
Correct |
294 ms |
347240 KB |
Output is correct |
18 |
Correct |
298 ms |
347300 KB |
Output is correct |
19 |
Correct |
301 ms |
347336 KB |
Output is correct |
20 |
Correct |
303 ms |
347256 KB |
Output is correct |
21 |
Correct |
302 ms |
347248 KB |
Output is correct |
22 |
Correct |
573 ms |
347172 KB |
Output is correct |
23 |
Correct |
555 ms |
347400 KB |
Output is correct |
24 |
Correct |
483 ms |
347320 KB |
Output is correct |
25 |
Correct |
505 ms |
347444 KB |
Output is correct |
26 |
Correct |
446 ms |
347324 KB |
Output is correct |
27 |
Correct |
356 ms |
347484 KB |
Output is correct |
28 |
Correct |
396 ms |
347324 KB |
Output is correct |
29 |
Correct |
490 ms |
347228 KB |
Output is correct |
30 |
Correct |
513 ms |
347500 KB |
Output is correct |