/**
____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|
**/
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const int maxn = 110, maxl = 1e3 + 10;
const ll mod = 1e9 + 7;
int n, l, a[maxn];
void add(ll &cell, ll val)
{
val %= mod;
cell += val;
if (cell >= mod)
cell -= mod;
}
ll dp[maxn][maxl][maxn][3];
void solve()
{
cin >> n >> l;
for (int i = 1; i <= n; i ++)
cin >> a[i];
sort(a + 1, a + n + 1);
a[n + 1] = a[n];
if (n == 1)
{
cout << 1 << endl;
return;
}
if (n == 2)
{
if (a[2] - a[1] <= l)
{
cout << 2 << endl;
}
else
{
cout << 0 << endl;
}
return;
}
dp[1][2 * a[2] - a[1]][1][0] = 1;
dp[1][a[2] - a[1]][1][1] = 1;
///cout << a[1] << " " << a[2] << endl;
for (int i = 1; i < n; i ++)
{
for (int j = 0; j <= l; j ++)
{
for (int k = 0; k <= n; k ++)
{
for (int p = 0; p < 3; p ++)
{
///cout << i << " " << j << " " << k << " " << p << " " << dp[i][j][k][p] << endl;
int new_diff = j + (k * 2 - p + 2) * (a[i + 2] - a[i + 1]);
///cout << new_diff << endl;
if (new_diff <= l)
add(dp[i + 1][new_diff][k + 1][p], dp[i][j][k][p] * (ll)(k + 1 - p));
new_diff = j + (k * 2 - p) * (a[i + 2] - a[i + 1]);
if (new_diff <= l)
add(dp[i + 1][new_diff][k][p], dp[i][j][k][p] * (ll)((k * 2 - p)));
if (p != 2)
{
new_diff = j + (k * 2 - p - 1) * (a[i + 2] - a[i + 1]);
if (new_diff <= l)
add(dp[i + 1][new_diff][k][p + 1], dp[i][j][k][p] * (2 - p));
}
new_diff = j + (k * 2 - p - 2) * (a[i + 2] - a[i + 1]);
if (new_diff <= l)
add(dp[i + 1][new_diff][k - 1][p], dp[i][j][k][p] * (k - 1));
}
}
}
}
ll ans = 0;
for (int s = 0; s <= l; s ++)
{
ans = ans + dp[n][s][1][2];
if (ans >= mod)
ans -= mod;
}
cout << (ans * 2)% mod << endl;
}
int main()
{
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2200 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |