#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int maxn = 105, mod = 1e9 + 7;
int mem[maxn][maxn][1005][2][2];
int ar[maxn], N, L;
void add(int & x, int y) {
x += y;
if (x >= mod) x -= mod;
if (x < 0) x += mod;
}
int calc(int pos, int cc, int curl, int havel, int haver) {
int nxtl = curl;
if (pos)
nxtl += (havel + haver + 2 * cc) * (ar[pos] - ar[pos - 1]);
if (nxtl > L)
return 0;
if (pos == N - 1) {
return (cc == 0 ? 1 : 0);
}
assert(cc >= 0);
int & res = mem[pos][cc][curl][havel][haver];
if (res != -1) return res;
res = 0;
/// connect start cc
add(res, calc(pos + 1, cc, nxtl, 1, haver));
/// merge with start cc and cc
if (cc) add(res, (ll)calc(pos + 1, cc - 1, nxtl, 1, haver) * cc % mod);
/// connect end cc
add(res, calc(pos + 1, cc, nxtl, havel, 1));
/// merge with end cc and cc
if (cc) add(res, (ll)calc(pos + 1, cc - 1, nxtl, havel, 1) * cc % mod);
/// new cc
add(res, calc(pos + 1, cc + 1, nxtl, havel, haver));
/// connect to cc
add(res, (ll)calc(pos + 1, cc, nxtl, havel, haver) * cc * 2 % mod);
/// merge 2 cc
if (cc) add(res, (ll)calc(pos + 1, cc - 1, nxtl, havel, haver) * cc * (cc - 1) % mod);
return res;
}
signed main(void) {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
freopen("A.INP", "r", stdin);
freopen("A.OUT", "w", stdout);
#endif // LOCAL
cin >> N >> L;
for (int i = 0; i < N; ++i) {
cin >> ar[i];
}
sort(ar, ar + N);
memset(mem, -1, sizeof mem);
cout << calc(0, 0, 0, 0, 0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
173816 KB |
Output is correct |
2 |
Correct |
89 ms |
173816 KB |
Output is correct |
3 |
Correct |
92 ms |
173816 KB |
Output is correct |
4 |
Correct |
91 ms |
173816 KB |
Output is correct |
5 |
Correct |
93 ms |
173852 KB |
Output is correct |
6 |
Correct |
92 ms |
173816 KB |
Output is correct |
7 |
Correct |
88 ms |
173816 KB |
Output is correct |
8 |
Correct |
90 ms |
173816 KB |
Output is correct |
9 |
Correct |
90 ms |
173816 KB |
Output is correct |
10 |
Correct |
89 ms |
173860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
92 ms |
173816 KB |
Output is correct |
2 |
Correct |
97 ms |
173820 KB |
Output is correct |
3 |
Correct |
90 ms |
173816 KB |
Output is correct |
4 |
Correct |
89 ms |
173820 KB |
Output is correct |
5 |
Correct |
89 ms |
173772 KB |
Output is correct |
6 |
Correct |
89 ms |
173816 KB |
Output is correct |
7 |
Correct |
89 ms |
173816 KB |
Output is correct |
8 |
Correct |
92 ms |
173816 KB |
Output is correct |
9 |
Correct |
90 ms |
173816 KB |
Output is correct |
10 |
Correct |
90 ms |
173740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
173816 KB |
Output is correct |
2 |
Correct |
89 ms |
173816 KB |
Output is correct |
3 |
Correct |
92 ms |
173816 KB |
Output is correct |
4 |
Correct |
91 ms |
173816 KB |
Output is correct |
5 |
Correct |
93 ms |
173852 KB |
Output is correct |
6 |
Correct |
92 ms |
173816 KB |
Output is correct |
7 |
Correct |
88 ms |
173816 KB |
Output is correct |
8 |
Correct |
90 ms |
173816 KB |
Output is correct |
9 |
Correct |
90 ms |
173816 KB |
Output is correct |
10 |
Correct |
89 ms |
173860 KB |
Output is correct |
11 |
Correct |
92 ms |
173816 KB |
Output is correct |
12 |
Correct |
97 ms |
173820 KB |
Output is correct |
13 |
Correct |
90 ms |
173816 KB |
Output is correct |
14 |
Correct |
89 ms |
173820 KB |
Output is correct |
15 |
Correct |
89 ms |
173772 KB |
Output is correct |
16 |
Correct |
89 ms |
173816 KB |
Output is correct |
17 |
Correct |
89 ms |
173816 KB |
Output is correct |
18 |
Correct |
92 ms |
173816 KB |
Output is correct |
19 |
Correct |
90 ms |
173816 KB |
Output is correct |
20 |
Correct |
90 ms |
173740 KB |
Output is correct |
21 |
Correct |
89 ms |
173816 KB |
Output is correct |
22 |
Correct |
392 ms |
173948 KB |
Output is correct |
23 |
Correct |
300 ms |
173816 KB |
Output is correct |
24 |
Correct |
296 ms |
174072 KB |
Output is correct |
25 |
Correct |
305 ms |
173860 KB |
Output is correct |
26 |
Correct |
271 ms |
173816 KB |
Output is correct |
27 |
Correct |
167 ms |
173820 KB |
Output is correct |
28 |
Correct |
202 ms |
173816 KB |
Output is correct |
29 |
Correct |
316 ms |
173944 KB |
Output is correct |
30 |
Correct |
315 ms |
173816 KB |
Output is correct |