#include <bits/stdc++.h>
using namespace std;
#define int long long
#define inf 0x3F3F3F3F3F3F3F3F
const int MXN = 1e3 + 5;
const int mod = 1e9 + 7;
int dp[MXN][MXN][2][2], ndp[MXN][MXN][2][2];
void _()
{
int n, L;
cin >> n >> L;
int arr[n];
for (int &i : arr) cin >> i;
sort(arr, arr + n);
dp[0][1][0][0] = dp[0][1][1][0] = dp[0][1][0][1] = dp[0][1][1][1] = 1;
int prv = 0;
for (int &i : arr)
{
int val = i - prv;
if (!prv) {prv = i; continue;}
prv = i;
for (int sum = 0; sum <= L; sum++) for (int c = 0; c <= n; c++) for (int f = 0; f < 2; f++) for (int b = 0; b < 2; b++)
{
if (!dp[sum][c][f][b]) continue;
if (c < f + b) continue;
int all = 2 * c - f - b;
int nw = sum + val * all;
if (nw > L) continue;
int X = dp[sum][c][f][b];
if (!f)
{
ndp[nw][c][1][b] += X, ndp[nw][c][1][b] %= mod;
if (c + 1 <= n) ndp[nw][c + 1][1][b] += X, ndp[nw][c + 1][1][b] %= mod;
}
if (!b)
{
ndp[nw][c][f][1] += X, ndp[nw][c][f][1] %= mod;
if (c + 1 <= n) ndp[nw][c + 1][f][1] += X, ndp[nw][c + 1][f][1] %= mod;
}
ndp[nw][c][f][b] += X * (2 * c - f - b) % mod, ndp[nw][c][f][b] %= mod;
if (c + 1 <= n) ndp[nw][c + 1][f][b] += X * (c + 1 - f - b) % mod, ndp[nw][c + 1][f][b] %= mod;
if (c >= 2) ndp[nw][c - 1][f][b] += X * (c - 1) % mod, ndp[nw][c - 1][f][b] %= mod;
}
for (int sum = 0; sum <= L; sum++) for (int c = 0; c <= n; c++) for (int f = 0; f < 2; f++) for (int b = 0; b < 2; b++) dp[sum][c][f][b] = ndp[sum][c][f][b], ndp[sum][c][f][b] = 0;
}
int res = 0;
for (int i = 0; i <= L; i++)
{
res += dp[i][1][1][1];
res %= mod;
}
cout << res << '\n';
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
while (t--) _();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |