This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
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[1][1][1] = 1;
for (int i = 2; i <= N; i++) {
for (int open = 1; open <= N; open++) {
for (int len = 1; len <= L; len++) {
dp[i][open+1][len + 1] = (dp[i][open+1][len + 1] + dp[i-1][open][len]) % MOD;
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) % MOD;
}
}
}
ll ans = 0;
for (int d = 1; d <= L; d++) {
ll ways = dp[N][1][d];
ans = (ans + ways * dist(L - d, N+1)) % MOD;
}
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |