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>
#pragma GCC optimize("O3")
#define ll long long
#define pii pair<int, int>
using namespace std;
const int MOD = 1e9 + 7;
const int MAX = 1e4 + 100;
int comb[MAX][MAX];
int dp[55][55][MAX];
int arr[55];
void preCalc(){
comb[0][0] = 1;
for (int i = 1; i < MAX; i++)
{
comb[i][0] = 1;
for (int j = 1; j <= i; j++)
{
comb[i][j] = ((comb[i][j] + comb[i - 1][j]) % MOD + comb[i - 1][j - 1]) % MOD;
}
}
}
int main(){
preCalc();
int n, l; cin >> n >> l;
for (int i = 0; i < n; i++)
{
cin >> arr[i + 1];
}
sort(arr + 1, arr + n + 1);
dp[0][0][1] = 1;
for (int i = 1; i <= n; i++)
{
int r = arr[i];
for (int j = 1; j <= i; j++)
{
for (int d = 1; d <= l; d++)
{
dp[i][j][d] += (1ll * dp[i - 1][j - 1][d] * j) % MOD;
if(r <= d){
dp[i][j][d] += 1ll * dp[i - 1][j][d - r] * (2 * j) % MOD;
}
dp[i][j][d] %= MOD;
if(2 * r <= d){
dp[i][j][d] += (1ll * dp[i - 1][j + 1][d - 2 * r] * j) % MOD;
}
dp[i][j][d] %= MOD;
}
}
}
int ans = 0;
for (int d = 1; d <= l; d++)
{
ans += 1ll * dp[n][1][d] * comb[l - d + n][n] % MOD;
ans %= 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... |