#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll LOGN = 20;
const ll MAXN = 24000;
ll expo(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1)
res = (res * a) % MOD;
a = (a * a) % MOD;
b /= 2;
}
return res;
}
ll fact[MAXN], inv[MAXN];
ll dp[55][55][MAXN];
ll nCr(ll n, ll r) {
if (r > n)
return 0LL;
if (r == n || r == 1 || r == 0)
return 1LL;
return ((fact[n] * inv[r]) % MOD * inv[n-r]) % MOD;
}
ll dist(ll item, ll plc) {
return nCr(item + plc - 1, item);
}
vector<ll> seq;
int main() {
fast
fact[0] = inv[0] = 1;
for (ll i = 1; i < MAXN; i++) {
fact[i] = (fact[i-1] * i) % MOD;
inv[i] = expo(fact[i], MOD-2);
}
ll N, L;
cin >> N >> L;
seq = vector<ll>(N);
for (int i = 0; i < N; i++)
cin >> seq[i];
sort(seq.begin(), seq.end());
dp[0][0][0] = 1;
for (int i = 1; i <= N; i++) {
for (int open = 0; open <= N; open++) {
if (i != 1 && open == 0)
continue;
for (int len = 0; len <= L; len++) {
dp[i][open+1][len + 1] = (dp[i][open+1][len + 1] + dp[i-1][open][len]) % MOD;
if (open != 0)
dp[i][open][len + seq[i-1]] = (dp[i][open][len + seq[i-1]] + 2 * open * dp[i-1][open][len]) % MOD;
if (open > 1)
dp[i][open-1][len + 2 * seq[i-1] - 1] = (dp[i][open-1][len + 2 * seq[i-1] - 1] + open * (open-1) * dp[i-1][open][len]) % MOD;
}
}
}
ll ans = 0;
for (int d = 1; d <= L; d++) {
ll ways = dp[N][1][d];
ll open = L - d;
ans = (ans + ways * dist(open, N+1)) % MOD;
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
210 ms |
213840 KB |
Output is correct |
2 |
Correct |
11 ms |
14940 KB |
Output is correct |
3 |
Correct |
11 ms |
11608 KB |
Output is correct |
4 |
Correct |
5 ms |
4184 KB |
Output is correct |
5 |
Correct |
15 ms |
15448 KB |
Output is correct |
6 |
Correct |
62 ms |
64936 KB |
Output is correct |
7 |
Correct |
149 ms |
208824 KB |
Output is correct |
8 |
Correct |
3 ms |
2648 KB |
Output is correct |
9 |
Correct |
84 ms |
135616 KB |
Output is correct |
10 |
Correct |
3 ms |
2648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
12300 KB |
Output is correct |
2 |
Correct |
4 ms |
3160 KB |
Output is correct |
3 |
Correct |
12 ms |
12632 KB |
Output is correct |
4 |
Correct |
4 ms |
3932 KB |
Output is correct |
5 |
Incorrect |
12 ms |
12632 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
9048 KB |
Output is correct |
2 |
Correct |
6 ms |
5208 KB |
Output is correct |
3 |
Correct |
9 ms |
9048 KB |
Output is correct |
4 |
Correct |
6 ms |
5720 KB |
Output is correct |
5 |
Incorrect |
8 ms |
9048 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
210 ms |
213840 KB |
Output is correct |
2 |
Correct |
11 ms |
14940 KB |
Output is correct |
3 |
Correct |
11 ms |
11608 KB |
Output is correct |
4 |
Correct |
5 ms |
4184 KB |
Output is correct |
5 |
Correct |
15 ms |
15448 KB |
Output is correct |
6 |
Correct |
62 ms |
64936 KB |
Output is correct |
7 |
Correct |
149 ms |
208824 KB |
Output is correct |
8 |
Correct |
3 ms |
2648 KB |
Output is correct |
9 |
Correct |
84 ms |
135616 KB |
Output is correct |
10 |
Correct |
3 ms |
2648 KB |
Output is correct |
11 |
Correct |
12 ms |
12300 KB |
Output is correct |
12 |
Correct |
4 ms |
3160 KB |
Output is correct |
13 |
Correct |
12 ms |
12632 KB |
Output is correct |
14 |
Correct |
4 ms |
3932 KB |
Output is correct |
15 |
Incorrect |
12 ms |
12632 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |