#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
const int MOD = 1e9 + 7, MAXN = 107;
int dp[MAXN][MAXN][1007][4] = {}, n, l, a[MAXN];
void add(int &a, const int &b)
{
a += b;
if (a >= MOD) a -= MOD;
}
int main()
{
// freopen("test.INP","r", stdin);
// freopen("BAILAM.OUT","w",stdout);
io;
cin >> n >> l;
for (int i = 1; i <= n; ++i) cin >> a[i];
sort(a + 1, a + 1 + n);
if (n == 1)
{
cout << 1;
return 0;
}
a[n + 1] = 10000;
if (a[2] - a[1] <= l) dp[2][1][a[2] - a[1]][1] = 2;//dat o a[1] o mot dau
if (n > 2 && 2*(a[2] - a[1]) <= l) dp[2][1][2*(a[2] - a[1])][0] = 1;//dat a[1] o giua
for (int i = 2; i <= n; ++i)
for (int j = 1; j <= i; ++j)
for (int k = 0; k <= l; ++k)
for (int z = 0; z < 3; ++z)
if (dp[i][j][k][z])
{
int diff = a[i + 1] - a[i], cur = dp[i][j][k][z];
int nwk = k + (2*j - z - 1)*diff;
//dat endpoint
if (z < 2)
{
//noi vao mot tplt
if (nwk <= l)
{
if (i == n)
{
//diem cuoi co the noi 2 endpoints
add(dp[i + 1][j][nwk][z + 1], 1LL*cur*(2 - z)*j % MOD);
}else
{
//khong noi duoc 2 endpoints
add(dp[i + 1][j][nwk][z + 1], 1LL*cur*(2 - z)*(j - z) % MOD);
}
}
//tao tplt moi
nwk = k + (2*j - z + 1)*diff;
if (nwk <= l) add(dp[i + 1][j + 1][nwk][z + 1], (2 - z)*cur % MOD);
}
//khong dat endpoint
//tao tplt moi
nwk = k + (2*j - z + 2)*diff;
if (nwk <= l) add(dp[i + 1][j + 1][nwk][z], cur);
//noi vao 1 tplt
nwk = k + (2*j - z)*diff;
if (nwk <= l) add(dp[i + 1][j][nwk][z], 1LL*(2*j - z)*cur % MOD);
//noi 2 tplt
nwk = k + (2*j - z - 2)*diff;
if (nwk <= l && j > 1 && ((i == n) || (z < 2) || (j > 2)))
{
if (z == 0)
{
add(dp[i + 1][j - 1][nwk][z], 1LL*j*(j - 1)*cur % MOD);
}
if (z == 1)
{
// if (i == 3 && j == 1 && k == 2 && z == 1) cout << 2*j - z - 2 << '\n';
add(dp[i + 1][j - 1][nwk][z], 1LL*(j - 1)*(j - 1)*cur % MOD);
}
if (z == 2)
{
if (i == n)
{
add(dp[i + 1][j - 1][nwk][z], cur);
}else
{
add(dp[i + 1][j - 1][nwk][z], 1LL*(j - 2)*(j - 1)*cur % MOD);
}
}
}
}
int res = 0;
for (int i = 0; i <= l; ++i) add(res, dp[n + 1][1][i][2]);
cout << res;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
0 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
640 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
640 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
640 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
640 KB |
Output is correct |
9 |
Correct |
1 ms |
640 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
0 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
640 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
1 ms |
640 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
1 ms |
640 KB |
Output is correct |
17 |
Correct |
1 ms |
512 KB |
Output is correct |
18 |
Correct |
1 ms |
640 KB |
Output is correct |
19 |
Correct |
1 ms |
640 KB |
Output is correct |
20 |
Correct |
1 ms |
512 KB |
Output is correct |
21 |
Correct |
2 ms |
1152 KB |
Output is correct |
22 |
Correct |
64 ms |
17912 KB |
Output is correct |
23 |
Correct |
44 ms |
6264 KB |
Output is correct |
24 |
Correct |
46 ms |
9464 KB |
Output is correct |
25 |
Correct |
48 ms |
7160 KB |
Output is correct |
26 |
Correct |
41 ms |
6780 KB |
Output is correct |
27 |
Correct |
23 ms |
8316 KB |
Output is correct |
28 |
Correct |
30 ms |
10104 KB |
Output is correct |
29 |
Correct |
49 ms |
13048 KB |
Output is correct |
30 |
Correct |
48 ms |
7472 KB |
Output is correct |