#include<bits/stdc++.h>
using namespace std;
const int N = 105, mod = 1e9 + 7;
int n, k, a[N], dp[N][N][1005][3];
int yo(int i, int c, int sum, int ends) { //(id, components, sum, borders)
if (ends > 2 || sum > k)return 0;
if (c == 0 && i > 1) return 0;
if (i == n + 1) return ends == 2 && c == 1;
int &ret = dp[i][c][sum][ends];
if (ret != -1) return ret;
int nsum = sum + (a[i] - a[i - 1]) * (2 * c - ends);
long long ans = 0;
if (c >= 2) ans += 1LL * (c - 1) * yo(i + 1, c - 1, nsum , ends); //merge two components
if (c >= 1) ans += 1LL * (2 * c - ends) * yo(i + 1, c, nsum , ends); //add to a component's end
ans += 1LL * (c + 1 - ends) * yo(i + 1, c + 1, nsum , ends); //create a new component
if (ends < 2) ans += 1LL * (2 - ends) * yo(i + 1, c + 1, nsum , ends + 1); //create a new end
if (ends < 2) ans += 1LL * (2 - ends) * yo(i + 1, c, nsum , ends + 1); //extend a component to make it a border
ans %= mod;
return ret = ans;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + n + 1);
if (n == 1) return cout << 1 << '\n', 0;
memset(dp, -1, sizeof dp);
cout << yo(1, 0, 0, 0) << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
72 ms |
130424 KB |
Output is correct |
3 |
Correct |
73 ms |
130424 KB |
Output is correct |
4 |
Correct |
72 ms |
130424 KB |
Output is correct |
5 |
Correct |
72 ms |
130424 KB |
Output is correct |
6 |
Correct |
71 ms |
130424 KB |
Output is correct |
7 |
Correct |
71 ms |
130380 KB |
Output is correct |
8 |
Correct |
71 ms |
130424 KB |
Output is correct |
9 |
Correct |
73 ms |
130424 KB |
Output is correct |
10 |
Correct |
71 ms |
130424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
130424 KB |
Output is correct |
2 |
Correct |
72 ms |
130424 KB |
Output is correct |
3 |
Correct |
72 ms |
130424 KB |
Output is correct |
4 |
Correct |
73 ms |
130424 KB |
Output is correct |
5 |
Correct |
70 ms |
130424 KB |
Output is correct |
6 |
Correct |
72 ms |
130424 KB |
Output is correct |
7 |
Correct |
71 ms |
130424 KB |
Output is correct |
8 |
Correct |
72 ms |
130424 KB |
Output is correct |
9 |
Correct |
71 ms |
130424 KB |
Output is correct |
10 |
Correct |
71 ms |
130552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
72 ms |
130424 KB |
Output is correct |
3 |
Correct |
73 ms |
130424 KB |
Output is correct |
4 |
Correct |
72 ms |
130424 KB |
Output is correct |
5 |
Correct |
72 ms |
130424 KB |
Output is correct |
6 |
Correct |
71 ms |
130424 KB |
Output is correct |
7 |
Correct |
71 ms |
130380 KB |
Output is correct |
8 |
Correct |
71 ms |
130424 KB |
Output is correct |
9 |
Correct |
73 ms |
130424 KB |
Output is correct |
10 |
Correct |
71 ms |
130424 KB |
Output is correct |
11 |
Correct |
71 ms |
130424 KB |
Output is correct |
12 |
Correct |
72 ms |
130424 KB |
Output is correct |
13 |
Correct |
72 ms |
130424 KB |
Output is correct |
14 |
Correct |
73 ms |
130424 KB |
Output is correct |
15 |
Correct |
70 ms |
130424 KB |
Output is correct |
16 |
Correct |
72 ms |
130424 KB |
Output is correct |
17 |
Correct |
71 ms |
130424 KB |
Output is correct |
18 |
Correct |
72 ms |
130424 KB |
Output is correct |
19 |
Correct |
71 ms |
130424 KB |
Output is correct |
20 |
Correct |
71 ms |
130552 KB |
Output is correct |
21 |
Correct |
74 ms |
130556 KB |
Output is correct |
22 |
Correct |
135 ms |
130424 KB |
Output is correct |
23 |
Correct |
108 ms |
130424 KB |
Output is correct |
24 |
Correct |
108 ms |
130424 KB |
Output is correct |
25 |
Correct |
107 ms |
130428 KB |
Output is correct |
26 |
Correct |
101 ms |
130424 KB |
Output is correct |
27 |
Correct |
91 ms |
130424 KB |
Output is correct |
28 |
Correct |
94 ms |
130424 KB |
Output is correct |
29 |
Correct |
120 ms |
130424 KB |
Output is correct |
30 |
Correct |
107 ms |
130424 KB |
Output is correct |