#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 102;
const int MAXL = 1002;
const ll MOD = 1e9+7;
#define upd(x, a) ((x) = ((x) + (a)) % MOD)
int N, L;
vector<int> v;
ll dp[MAXN][MAXN][3][MAXL];
int main()
{
ios_base::sync_with_stdio(0);
cin >> N >> L;
v.resize(N);
for (int i = 0; i < N; i++) cin >> v[i];
sort(v.begin(), v.end());
if (N == 1) return cout << 1 << endl, 0;
v.push_back(MAXL*100);
if (v[1] - v[0] <= L) dp[1][1][1][v[1]-v[0]] = 2;
if (2*(v[1] - v[0]) <= L) dp[1][1][0][2*(v[1]-v[0])] = 1;
int nsum; ll cur;
for (int i = 1; i <= N; i++) {
int dif = v[i+1] - v[i];
for (int cnt = 1; cnt <= i; cnt++) {
for (int end = 0; end < 3; end++) {
for (int sum = 0; sum <= L; sum++) {
cur = dp[i][cnt][end][sum];
if (cur == 0) continue;
// try to fill the ends
nsum = sum + dif*(2*cnt - end - 1);
if (end < 2 && nsum <= L) {
// no new component is created
if (i == N-1) upd(dp[i+1][cnt][end+1][nsum], cur);
else if (end == 0 || cnt > 1) upd(dp[i+1][cnt][end+1][nsum], ll(2-end)*ll(cnt-end)*cur);
// a new component is created
nsum += 2*dif;
if (nsum <= L) upd(dp[i+1][cnt+1][end+1][nsum], ll(2-end)*cur);
}
// try to create a new component
nsum = sum + dif*(2*cnt - end) + 2*dif;
if (nsum <= L) upd(dp[i+1][cnt+1][end][nsum], cur);
// try append to a component
nsum = sum + dif*(2*cnt - end);
if (nsum <= L) upd(dp[i+1][cnt][end][nsum], ll(2*cnt-end)*cur);
// join two components together
nsum = sum + dif*(2*cnt - end) - 2*dif;
if (nsum <= L && cnt >= 2 && (i == N-1 || cnt > 2 || end < 2)) {
if (end == 0) upd(dp[i+1][cnt-1][end][nsum], ll(cnt)*ll(cnt-1)*cur);
else if (end == 1) upd(dp[i+1][cnt-1][end][nsum], ll(cnt-1)*ll(cnt-1)*cur);
else if (end == 2) {
if (i == N-1) upd(dp[i+1][cnt-1][end][nsum], cur);
else upd(dp[i+1][cnt-1][end][nsum], ll(cnt-2)*ll(cnt-1)*cur);
}
}
}
}
}
}
ll ans = 0;
for (int i = 0; i <= L; i++)
upd(ans, dp[N][1][2][i]);
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
246516 KB |
Output is correct |
2 |
Correct |
0 ms |
246516 KB |
Output is correct |
3 |
Correct |
0 ms |
246516 KB |
Output is correct |
4 |
Correct |
0 ms |
246516 KB |
Output is correct |
5 |
Correct |
0 ms |
246516 KB |
Output is correct |
6 |
Correct |
0 ms |
246516 KB |
Output is correct |
7 |
Correct |
0 ms |
246516 KB |
Output is correct |
8 |
Correct |
0 ms |
246516 KB |
Output is correct |
9 |
Correct |
0 ms |
246516 KB |
Output is correct |
10 |
Correct |
0 ms |
246516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
246516 KB |
Output is correct |
2 |
Correct |
0 ms |
246516 KB |
Output is correct |
3 |
Correct |
0 ms |
246516 KB |
Output is correct |
4 |
Correct |
0 ms |
246516 KB |
Output is correct |
5 |
Correct |
0 ms |
246516 KB |
Output is correct |
6 |
Correct |
0 ms |
246516 KB |
Output is correct |
7 |
Correct |
0 ms |
246516 KB |
Output is correct |
8 |
Correct |
0 ms |
246516 KB |
Output is correct |
9 |
Correct |
0 ms |
246516 KB |
Output is correct |
10 |
Correct |
0 ms |
246516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
246516 KB |
Output is correct |
2 |
Correct |
0 ms |
246516 KB |
Output is correct |
3 |
Correct |
0 ms |
246516 KB |
Output is correct |
4 |
Correct |
0 ms |
246516 KB |
Output is correct |
5 |
Correct |
0 ms |
246516 KB |
Output is correct |
6 |
Correct |
0 ms |
246516 KB |
Output is correct |
7 |
Correct |
0 ms |
246516 KB |
Output is correct |
8 |
Correct |
0 ms |
246516 KB |
Output is correct |
9 |
Correct |
0 ms |
246516 KB |
Output is correct |
10 |
Correct |
0 ms |
246516 KB |
Output is correct |
11 |
Correct |
0 ms |
246516 KB |
Output is correct |
12 |
Correct |
0 ms |
246516 KB |
Output is correct |
13 |
Correct |
0 ms |
246516 KB |
Output is correct |
14 |
Correct |
0 ms |
246516 KB |
Output is correct |
15 |
Correct |
0 ms |
246516 KB |
Output is correct |
16 |
Correct |
0 ms |
246516 KB |
Output is correct |
17 |
Correct |
0 ms |
246516 KB |
Output is correct |
18 |
Correct |
0 ms |
246516 KB |
Output is correct |
19 |
Correct |
0 ms |
246516 KB |
Output is correct |
20 |
Correct |
0 ms |
246516 KB |
Output is correct |
21 |
Correct |
0 ms |
246516 KB |
Output is correct |
22 |
Correct |
26 ms |
246516 KB |
Output is correct |
23 |
Correct |
23 ms |
246516 KB |
Output is correct |
24 |
Correct |
23 ms |
246516 KB |
Output is correct |
25 |
Correct |
16 ms |
246516 KB |
Output is correct |
26 |
Correct |
13 ms |
246516 KB |
Output is correct |
27 |
Correct |
13 ms |
246516 KB |
Output is correct |
28 |
Correct |
26 ms |
246516 KB |
Output is correct |
29 |
Correct |
39 ms |
246516 KB |
Output is correct |
30 |
Correct |
23 ms |
246516 KB |
Output is correct |