#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i<= b; ++i)
#define FORD(i, a, b) for (int i = a; i>=b; --i)
#define REP(i, a) for (int i = 0; i<a; ++i)
#define DEBUG(x) { cerr << #x << " = " << x << endl; }
#define Arr(A, l, r) { cerr << #A << " = "; FOR(_, l, r) cerr << A[_] << ' '; cerr << endl; }
#define N 111
#define pp pair<int, int>
#define next __next
#define prev __prev
#define __builtin_popcount __builtin_popcountll
#define bit(S, i) (((S) >> i) & 1)
#define IO cin.tie(NULL);cout.tie(NULL);
using namespace std;
int n, a[N], lim;
const int MOD = 1e9 + 7;
bool used[N][N][N * 10][2][2];
int dp[N][N][N * 10][2][2];
// 1 : Put u positions
// 2 : Now have cc connected components
// 3 : Different equal diff
// 4 : Front is chosen
// 5 : Back is chosen
void Add(int &a, int b) { a += b; if (a >= MOD) a -= MOD; }
int Mul(int a, int b) { return 1ll * a * b % MOD; }
int cal(int u, int cc, int diff, int fc, int bc) {
diff += u == 0 ? 0 : (a[u] - a[u - 1]) * (2 * cc - fc - bc);
if (diff > lim) return 0;
if (u == n) {
if (!(fc & bc)) return 0;
return cc == 1;
}
if (used[u][cc][diff][fc][bc]) return dp[u][cc][diff][fc][bc];
used[u][cc][diff][fc][bc] = 1;
int &ret = dp[u][cc][diff][fc][bc] = 0;
// Create new connected component
Add(ret, Mul(cal(u + 1, cc + 1, diff, fc, bc), cc + 1 - fc - bc));
// At front
if (!fc) Add(ret, cal(u + 1, cc + 1, diff, 1, bc));
// At back
if (!bc) Add(ret, cal(u + 1, cc + 1, diff, fc, 1));
if (cc > 0) {
// Connect two components
if (cc > 1) Add(ret, Mul(cal(u + 1, cc - 1, diff, fc, bc), cc - 1));
//Enlarge connected component
Add(ret, Mul(cal(u + 1, cc, diff, fc, bc), 2 * cc - fc - bc));
// At front
if (!fc) Add(ret, cal(u + 1, cc, diff, 1, bc));
// At back
if (!bc) Add(ret, cal(u + 1, cc, diff, fc, 1));
}
return ret;
}
int main() {
IO;
cin >> n >> lim;
REP(i, n) cin >> a[i];
if (n == 1) {
cout << 1;
return 0;
}
sort(a, a + n);
cout << cal(0, 0, 0, 0, 0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
269136 KB |
Output is correct |
2 |
Correct |
0 ms |
269136 KB |
Output is correct |
3 |
Correct |
0 ms |
269136 KB |
Output is correct |
4 |
Correct |
0 ms |
269136 KB |
Output is correct |
5 |
Correct |
0 ms |
269136 KB |
Output is correct |
6 |
Correct |
0 ms |
269136 KB |
Output is correct |
7 |
Correct |
0 ms |
269136 KB |
Output is correct |
8 |
Correct |
0 ms |
269136 KB |
Output is correct |
9 |
Correct |
0 ms |
269136 KB |
Output is correct |
10 |
Correct |
0 ms |
269136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
269136 KB |
Output is correct |
2 |
Correct |
1 ms |
269136 KB |
Output is correct |
3 |
Correct |
1 ms |
269136 KB |
Output is correct |
4 |
Correct |
1 ms |
269136 KB |
Output is correct |
5 |
Correct |
1 ms |
269136 KB |
Output is correct |
6 |
Correct |
1 ms |
269136 KB |
Output is correct |
7 |
Correct |
0 ms |
269136 KB |
Output is correct |
8 |
Correct |
1 ms |
269136 KB |
Output is correct |
9 |
Correct |
1 ms |
269136 KB |
Output is correct |
10 |
Correct |
1 ms |
269136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
269136 KB |
Output is correct |
2 |
Correct |
0 ms |
269136 KB |
Output is correct |
3 |
Correct |
0 ms |
269136 KB |
Output is correct |
4 |
Correct |
0 ms |
269136 KB |
Output is correct |
5 |
Correct |
0 ms |
269136 KB |
Output is correct |
6 |
Correct |
0 ms |
269136 KB |
Output is correct |
7 |
Correct |
0 ms |
269136 KB |
Output is correct |
8 |
Correct |
0 ms |
269136 KB |
Output is correct |
9 |
Correct |
0 ms |
269136 KB |
Output is correct |
10 |
Correct |
0 ms |
269136 KB |
Output is correct |
11 |
Correct |
1 ms |
269136 KB |
Output is correct |
12 |
Correct |
1 ms |
269136 KB |
Output is correct |
13 |
Correct |
1 ms |
269136 KB |
Output is correct |
14 |
Correct |
1 ms |
269136 KB |
Output is correct |
15 |
Correct |
1 ms |
269136 KB |
Output is correct |
16 |
Correct |
1 ms |
269136 KB |
Output is correct |
17 |
Correct |
0 ms |
269136 KB |
Output is correct |
18 |
Correct |
1 ms |
269136 KB |
Output is correct |
19 |
Correct |
1 ms |
269136 KB |
Output is correct |
20 |
Correct |
1 ms |
269136 KB |
Output is correct |
21 |
Correct |
3 ms |
269136 KB |
Output is correct |
22 |
Correct |
329 ms |
269136 KB |
Output is correct |
23 |
Correct |
151 ms |
269136 KB |
Output is correct |
24 |
Correct |
150 ms |
269136 KB |
Output is correct |
25 |
Correct |
115 ms |
269136 KB |
Output is correct |
26 |
Correct |
115 ms |
269136 KB |
Output is correct |
27 |
Correct |
63 ms |
269136 KB |
Output is correct |
28 |
Correct |
116 ms |
269136 KB |
Output is correct |
29 |
Correct |
238 ms |
269136 KB |
Output is correct |
30 |
Correct |
112 ms |
269136 KB |
Output is correct |