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;
#pragma GCC optimize("Ofast")
#define int long long
const int mod = 1e9 + 7;
int32_t main()
{
int n, l;
cin >> n >> l;
if (n==1)
{
cout << 1;
return 0;
}
vector<int> nums(n);
for (int i = 0; i < n; i++)
{
cin >> nums[i];
}
sort(nums.begin(), nums.end());
vector<vector<vector<vector<int>>>> dp(2, vector<vector<vector<int>>>(l+1, vector<vector<int>>(n+1, vector<int>(3, 0))));
dp[1][0][1][0] = 1;
dp[1][0][1][1] = 2;
for (int i = 1; i < n; i++)
{
int ii = (i+1)%2;
int cc = (i)%2;
dp[ii].assign(l+1, vector<vector<int>>(n+1, vector<int>(3, 0)));
for (int j = 0; j <= l; j++)
{
for (int k = 1; k <= i; k++)
{
for (int m =0; m < 3; m++)
{
int nsum = j;
nsum = j+(k*2-m)*(nums[i]-nums[i-1]);
if(nsum > l) continue;
dp[ii][nsum][k][m] += dp[cc][j][k][m]*(k*2-m);
dp[ii][nsum][k-1][m] += dp[cc][j][k][m]*(k-1);
dp[ii][nsum][k+1][m] += dp[cc][j][k][m]*(k+1-m);
if(m!=2)
{
dp[ii][nsum][k+1][m+1] += dp[cc][j][k][m]*(2-m);
if(k) dp[ii][nsum][k][m+1] += dp[cc][j][k][m]*(2-m);
dp[ii][nsum][k+1][m+1]%=mod;
dp[ii][nsum][k][m+1]%=mod;
}
dp[ii][nsum][k][m]%=mod;
dp[ii][nsum][k-1][m]%=mod;
dp[ii][nsum][k+1][m]%=mod;
}
}
}
}
int sum = 0;
for (int i = 0; i <= l; i++)
{
sum += dp[n%2][i][1][2];
sum%=mod;
}
cout << sum;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |