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;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 105, L = 1005, MD = 1e9 + 7;
void add(int &a, int b) {
if ((a += b) >= MD) {
a -= MD;
}
}
int n, l;
int a[N], dp[N][N][L][3];
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> l;
if (n == 1) {
cout << 1;
exit(0);
}
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
a[n + 1] = 10000;
dp[0][0][0][0] = 1;
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= i; ++j) {
for (int k = 0; k <= l; ++k) {
for (int m = 0; m < 3; ++m) {
int dif = (a[i + 1] - a[i]) * (2 * j - m);
int &res = dp[i][j][k][m];
if (dif <= k && i + j + 1 - m <= n) {
add(res, dp[i - 1][j - 1][k - dif][m]);
add(res, (long long) (2 * j - m) * dp[i - 1][j][k - dif][m] % MD);
if (m > 0) {
add(res, (long long) (3 - m) * dp[i - 1][j - 1][k - dif][m - 1] % MD);
if (m == 1) {
add(res, 2LL * j * dp[i - 1][j][k - dif][m - 1] % MD);
} else {
if (i == n) {
if (j == 1) {
add(res, dp[i - 1][j][k - dif][m - 1]);
}
} else {
add(res, (long long) (j - 1) * dp[i - 1][j][k - dif][m - 1] % MD);
}
}
}
if (m == 2) {
if (i == n) {
add(res, dp[i - 1][j + 1][k - dif][m]);
} else {
add(res, (long long) j * (j - 1) * dp[i - 1][j + 1][k - dif][m] % MD);
}
} else if (m == 1) {
add(res, (long long) j * j * dp[i - 1][j + 1][k - dif][m] % MD);
} else {
add(res, (long long) j * (j + 1) * dp[i - 1][j + 1][k - dif][m] % MD);
}
}
}
}
}
}
int res = 0;
for (int k = 0; k <= l; ++k) {
add(res, dp[n][1][k][2]);
}
cout << res;
return 0;
}
// Thanks Usaco!!!
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |