#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e2 + 5;
const int mod = 1e9 + 7;
void add(int &a, int b) {
a += b;
if(a >= mod) a -= mod;
if(a < 0) a += mod;
}
int n, L, a[N];
int dp[N][N][N * 10][3];
void solve() {
cin >> n >> L;
for(int i = 1; i <= n; ++i) cin >> a[i];
if(n == 1) return cout << 1 << '\n', void();
sort(a + 1, a + n + 1);
dp[1][1][0][1] = 2;
dp[1][1][0][0] = 1;
for(int i = 2; i <= n; ++i) {
for(int j = 0; j <= i; ++j) {
for(int k = 0; k <= L; ++k) {
for(int z = 0; z <= 2; ++z) {
int cost = (2 * j - z) * (a[i] - a[i - 1]);
if(k + cost > L) continue;
// connect 2 components
if(j) add(dp[i][j - 1][k + cost][z], 1ll * (j - 1) * dp[i - 1][j][k][z] % mod);
// add a[i] at the beginning or end of one comp of permutation but don't lock
add(dp[i][j][k + cost][z], 1ll * (2 * j - z) * dp[i - 1][j][k][z] % mod);
// add a[i] at the beginning or end of one comp of permutation and lock
if(z < 2) add(dp[i][j][k + cost][z + 1], 1ll * (2 - z) * dp[i - 1][j][k][z] % mod);
// create new component
// add a[i] at the beginning or end of permutation but don't lock
add(dp[i][j + 1][k + cost][z], 1ll * (2 - z) * dp[i - 1][j][k][z] % mod);
// add a[i] at the beginning or end of permutation and lock
if(z < 2) add(dp[i][j + 1][k + cost][z + 1], 1ll * (2 - z) * dp[i - 1][j][k][z] % mod);
// add a[i] as a middle component
if(j >= 2) add(dp[i][j + 1][k + cost][z], 1ll * (j - 1) * dp[i - 1][j][k][z] % mod);
}
}
}
}
int res = 0;
for(int i = 0; i <= L; ++i) {
add(res, dp[n][1][i][2]);
}
cout << res << '\n';
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int test = 1;
// cin >> test;
while(test--) solve();
return 0;
}
// https://oj.uz/problem/view/JOI16_skyscraper
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2908 KB |
Output is correct |
6 |
Correct |
1 ms |
2908 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2648 KB |
Output is correct |
9 |
Correct |
2 ms |
2908 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2908 KB |
Output is correct |
2 |
Correct |
1 ms |
2908 KB |
Output is correct |
3 |
Correct |
1 ms |
2908 KB |
Output is correct |
4 |
Correct |
1 ms |
2908 KB |
Output is correct |
5 |
Correct |
1 ms |
2904 KB |
Output is correct |
6 |
Correct |
1 ms |
3116 KB |
Output is correct |
7 |
Correct |
1 ms |
2908 KB |
Output is correct |
8 |
Correct |
1 ms |
2908 KB |
Output is correct |
9 |
Correct |
1 ms |
2908 KB |
Output is correct |
10 |
Correct |
1 ms |
2904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2908 KB |
Output is correct |
6 |
Correct |
1 ms |
2908 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2648 KB |
Output is correct |
9 |
Correct |
2 ms |
2908 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2908 KB |
Output is correct |
12 |
Correct |
1 ms |
2908 KB |
Output is correct |
13 |
Correct |
1 ms |
2908 KB |
Output is correct |
14 |
Correct |
1 ms |
2908 KB |
Output is correct |
15 |
Correct |
1 ms |
2904 KB |
Output is correct |
16 |
Correct |
1 ms |
3116 KB |
Output is correct |
17 |
Correct |
1 ms |
2908 KB |
Output is correct |
18 |
Correct |
1 ms |
2908 KB |
Output is correct |
19 |
Correct |
1 ms |
2908 KB |
Output is correct |
20 |
Correct |
1 ms |
2904 KB |
Output is correct |
21 |
Correct |
3 ms |
5468 KB |
Output is correct |
22 |
Correct |
124 ms |
41968 KB |
Output is correct |
23 |
Correct |
120 ms |
48692 KB |
Output is correct |
24 |
Correct |
114 ms |
51536 KB |
Output is correct |
25 |
Correct |
126 ms |
48980 KB |
Output is correct |
26 |
Correct |
110 ms |
47956 KB |
Output is correct |
27 |
Correct |
55 ms |
35156 KB |
Output is correct |
28 |
Correct |
63 ms |
38484 KB |
Output is correct |
29 |
Correct |
113 ms |
51536 KB |
Output is correct |
30 |
Correct |
124 ms |
49044 KB |
Output is correct |