#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
const int mod = 1e9+7;
const int mxN = 105;
const int mxL = 1005;
const int mxA = 1005;
int N, L, A[mxN];
int res[mxN][mxN][mxL][3];
// processing ith element, j connected component, k cost, l ends open
int dp(int i, int j, int k, int l) {
if (k > L || l < 0) return 0;
if (i > N) return j == 1 && l == 0;
int& ans = res[i][j][k][l];
if (~ans) return ans;
ans = 0;
int opened = 2*j - 2 + l;
int kk = k + opened * (A[i]-A[i-1]);
// new cc
ans += (long long) (j+1 - 2 + l) * dp(i+1, j+1, kk, l) % mod;
ans %= mod;
ans += l * dp(i+1, j+1, kk, l-1) % mod;
ans %= mod;
if (j > 0) {
// append
ans += (long long) opened * dp(i+1, j, kk, l) % mod;
ans %= mod;
ans += l * dp(i+1, j, kk, l-1) % mod;
ans %= mod;
}
if (j > 1) {
// join
ans += (long long) (j-1) * dp(i+1, j-1, kk, l) % mod;
ans %= mod;
}
//TRACE(i _ j _ k _ l _ ans);
return ans;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> N >> L;
FOR(i,1,N){
cin >> A[i];
}
// corner case -- cannot close both ends simultaneously
if (N == 1) {
cout << 1 << '\n';
return 0;
}
sort(A+1,A+1+N);
memset(res,-1,sizeof res);
cout << dp(1,0,0,2) << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
56 ms |
130372 KB |
Output is correct |
3 |
Correct |
56 ms |
130340 KB |
Output is correct |
4 |
Correct |
56 ms |
130328 KB |
Output is correct |
5 |
Correct |
58 ms |
130372 KB |
Output is correct |
6 |
Correct |
56 ms |
130332 KB |
Output is correct |
7 |
Correct |
56 ms |
130316 KB |
Output is correct |
8 |
Correct |
66 ms |
130368 KB |
Output is correct |
9 |
Correct |
57 ms |
130304 KB |
Output is correct |
10 |
Correct |
56 ms |
130372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
130392 KB |
Output is correct |
2 |
Correct |
59 ms |
130376 KB |
Output is correct |
3 |
Correct |
57 ms |
130336 KB |
Output is correct |
4 |
Correct |
55 ms |
130372 KB |
Output is correct |
5 |
Correct |
61 ms |
130360 KB |
Output is correct |
6 |
Correct |
59 ms |
130348 KB |
Output is correct |
7 |
Correct |
57 ms |
130280 KB |
Output is correct |
8 |
Correct |
56 ms |
130384 KB |
Output is correct |
9 |
Correct |
57 ms |
130336 KB |
Output is correct |
10 |
Correct |
59 ms |
130384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
56 ms |
130372 KB |
Output is correct |
3 |
Correct |
56 ms |
130340 KB |
Output is correct |
4 |
Correct |
56 ms |
130328 KB |
Output is correct |
5 |
Correct |
58 ms |
130372 KB |
Output is correct |
6 |
Correct |
56 ms |
130332 KB |
Output is correct |
7 |
Correct |
56 ms |
130316 KB |
Output is correct |
8 |
Correct |
66 ms |
130368 KB |
Output is correct |
9 |
Correct |
57 ms |
130304 KB |
Output is correct |
10 |
Correct |
56 ms |
130372 KB |
Output is correct |
11 |
Correct |
55 ms |
130392 KB |
Output is correct |
12 |
Correct |
59 ms |
130376 KB |
Output is correct |
13 |
Correct |
57 ms |
130336 KB |
Output is correct |
14 |
Correct |
55 ms |
130372 KB |
Output is correct |
15 |
Correct |
61 ms |
130360 KB |
Output is correct |
16 |
Correct |
59 ms |
130348 KB |
Output is correct |
17 |
Correct |
57 ms |
130280 KB |
Output is correct |
18 |
Correct |
56 ms |
130384 KB |
Output is correct |
19 |
Correct |
57 ms |
130336 KB |
Output is correct |
20 |
Correct |
59 ms |
130384 KB |
Output is correct |
21 |
Correct |
55 ms |
130372 KB |
Output is correct |
22 |
Correct |
221 ms |
130396 KB |
Output is correct |
23 |
Correct |
130 ms |
130392 KB |
Output is correct |
24 |
Correct |
137 ms |
130328 KB |
Output is correct |
25 |
Correct |
152 ms |
130380 KB |
Output is correct |
26 |
Correct |
120 ms |
130404 KB |
Output is correct |
27 |
Correct |
94 ms |
130364 KB |
Output is correct |
28 |
Correct |
108 ms |
130396 KB |
Output is correct |
29 |
Correct |
160 ms |
130372 KB |
Output is correct |
30 |
Correct |
136 ms |
130312 KB |
Output is correct |