#include <bits/stdc++.h>
#define SZ(x) (((int)x.size()))
typedef long long ll;
using namespace std;
const int mod = 1000000007, maxn = 110, maxm = 55, maxl = 1*1000+10;
int dp[maxn][maxm][maxl][3], n, l, a[maxn], cost;
int main()
{
cin >> n >> l;
for (int i = 0; i < n; i++)
cin >> a[i];
if (n == 1)
{
cout << 1;
return 0;
}
sort(a, a + n);
for (int i = 0; i <= l; i++)
dp[0][0][i][0] = 1;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= min(i, (n + 1) / 2); j++)
{
for (int k = 0; k <= l; k++)
{
for (int m = 0; m < 3; m++)
{
cost = (j * 2 - m) * (a[i] - a[i - 1]);
if (cost > k)
continue;
if (m > 0)
{
dp[i][j][k][m] += (dp[i - 1][j][k - cost][m - 1] * (3 - m)) % mod;
dp[i][j][k][m] %= mod;
if (i + j + 1 - m <= n)
{
dp[i][j][k][m] += (dp[i - 1][j - 1][k - cost][m - 1] * (3 - m)) % mod;
dp[i][j][k][m] %= mod;
}
}
if (i + j + 1 - m <= n)
{
dp[i][j][k][m] += ((ll)dp[i - 1][j - 1][k - cost][m] * (j - m)) % mod;
dp[i][j][k][m] %= mod;
dp[i][j][k][m] += ((ll)dp[i - 1][j][k - cost][m] * (j * 2 - m)) % mod;
dp[i][j][k][m] %= mod;
}
if (j < (n + 1) / 2)
{
dp[i][j][k][m] += ((ll)dp[i - 1][j + 1][k - cost][m] * j) % mod;
dp[i][j][k][m] %= mod;
}
//cerr << i << " " << j << " " << k << " " << m << " " << dp[i][j][k][m] << endl;
}
}
}
}
cout << dp[n][1][l][2];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
380 KB |
Output is correct |
4 |
Correct |
2 ms |
400 KB |
Output is correct |
5 |
Correct |
4 ms |
760 KB |
Output is correct |
6 |
Correct |
4 ms |
632 KB |
Output is correct |
7 |
Correct |
3 ms |
532 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
3 ms |
632 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
632 KB |
Output is correct |
2 |
Correct |
3 ms |
632 KB |
Output is correct |
3 |
Correct |
3 ms |
632 KB |
Output is correct |
4 |
Correct |
3 ms |
632 KB |
Output is correct |
5 |
Correct |
3 ms |
632 KB |
Output is correct |
6 |
Correct |
3 ms |
632 KB |
Output is correct |
7 |
Correct |
3 ms |
632 KB |
Output is correct |
8 |
Correct |
3 ms |
632 KB |
Output is correct |
9 |
Correct |
3 ms |
760 KB |
Output is correct |
10 |
Correct |
3 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
380 KB |
Output is correct |
4 |
Correct |
2 ms |
400 KB |
Output is correct |
5 |
Correct |
4 ms |
760 KB |
Output is correct |
6 |
Correct |
4 ms |
632 KB |
Output is correct |
7 |
Correct |
3 ms |
532 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
3 ms |
632 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
3 ms |
632 KB |
Output is correct |
12 |
Correct |
3 ms |
632 KB |
Output is correct |
13 |
Correct |
3 ms |
632 KB |
Output is correct |
14 |
Correct |
3 ms |
632 KB |
Output is correct |
15 |
Correct |
3 ms |
632 KB |
Output is correct |
16 |
Correct |
3 ms |
632 KB |
Output is correct |
17 |
Correct |
3 ms |
632 KB |
Output is correct |
18 |
Correct |
3 ms |
632 KB |
Output is correct |
19 |
Correct |
3 ms |
760 KB |
Output is correct |
20 |
Correct |
3 ms |
632 KB |
Output is correct |
21 |
Correct |
6 ms |
2936 KB |
Output is correct |
22 |
Correct |
145 ms |
27840 KB |
Output is correct |
23 |
Correct |
199 ms |
36672 KB |
Output is correct |
24 |
Correct |
185 ms |
39160 KB |
Output is correct |
25 |
Correct |
210 ms |
37508 KB |
Output is correct |
26 |
Correct |
183 ms |
36564 KB |
Output is correct |
27 |
Correct |
81 ms |
24448 KB |
Output is correct |
28 |
Correct |
94 ms |
27000 KB |
Output is correct |
29 |
Correct |
162 ms |
37296 KB |
Output is correct |
30 |
Correct |
210 ms |
37668 KB |
Output is correct |