#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 100+1, L = 1000+1, mod = 1e9+7;
int n, l;
int a[N];
ll dp[N][N][L][3];
int main(){
ios_base::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
cin >> n >> l;
for(int i = 0; i < n; ++i)
cin >> a[i];
if(n == 1){
cout << "1\n";
return 0;
}
sort(a, a+n);
a[n] = L;
dp[0][0][0][0] = 1;
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j){
for(int k = 0; k <= l; ++k){
int dif;
// e = 0
dif = 2*j*(a[i]-a[i-1]);
if(dif <= k){
dp[i][j][k][0] = (dp[i][j][k][0] + dp[i-1][j-1][k - dif][0]*j)%mod;
dp[i][j][k][0] = (dp[i][j][k][0] + dp[i-1][j][k - dif][0]*2*j)%mod;
dp[i][j][k][0] = (dp[i][j][k][0] + dp[i-1][j+1][k - dif][0]*j)%mod;
}
// e = 1
dif = (2*j - 1)*(a[i] - a[i-1]);
if(dif <= k){
dp[i][j][k][1] = (dp[i][j][k][1] + dp[i-1][j-1][k - dif][0]*2)%mod;
dp[i][j][k][1] = (dp[i][j][k][1] + dp[i-1][j][k - dif][0]*2)%mod;
dp[i][j][k][1] = (dp[i][j][k][1] + dp[i-1][j-1][k - dif][1]*(j-1))%mod;
dp[i][j][k][1] = (dp[i][j][k][1] + dp[i-1][j][k - dif][1]*(2*j-1))%mod;
dp[i][j][k][1] = (dp[i][j][k][1] + dp[i-1][j+1][k - dif][1]*j)%mod;
}
// e = 2
dif = (2*j - 2)*(a[i] - a[i-1]);
if(dif <= k){
dp[i][j][k][2] = (dp[i][j][k][2] + dp[i-1][j-1][k - dif][1])%mod;
dp[i][j][k][2] = (dp[i][j][k][2] + dp[i-1][j][k - dif][1])%mod;
dp[i][j][k][2] = (dp[i][j][k][2] + dp[i-1][j-1][k - dif][2]*(j-2))%mod;
dp[i][j][k][2] = (dp[i][j][k][2] + dp[i-1][j][k - dif][2]*(2*j-2))%mod;
dp[i][j][k][2] = (dp[i][j][k][2] + dp[i-1][j+1][k - dif][2]*j)%mod;
}
}
}
}
ll ans = 0;
for(int i = 0; i <= l; ++i)
ans = (ans + dp[n][1][i][2])%mod;
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
1132 KB |
Output is correct |
6 |
Correct |
2 ms |
1132 KB |
Output is correct |
7 |
Correct |
1 ms |
620 KB |
Output is correct |
8 |
Correct |
1 ms |
620 KB |
Output is correct |
9 |
Correct |
3 ms |
1132 KB |
Output is correct |
10 |
Correct |
1 ms |
748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1132 KB |
Output is correct |
2 |
Correct |
1 ms |
1132 KB |
Output is correct |
3 |
Correct |
2 ms |
1260 KB |
Output is correct |
4 |
Correct |
1 ms |
1004 KB |
Output is correct |
5 |
Correct |
1 ms |
1132 KB |
Output is correct |
6 |
Correct |
2 ms |
1260 KB |
Output is correct |
7 |
Correct |
1 ms |
876 KB |
Output is correct |
8 |
Correct |
1 ms |
1260 KB |
Output is correct |
9 |
Correct |
2 ms |
1388 KB |
Output is correct |
10 |
Correct |
1 ms |
1132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
1132 KB |
Output is correct |
6 |
Correct |
2 ms |
1132 KB |
Output is correct |
7 |
Correct |
1 ms |
620 KB |
Output is correct |
8 |
Correct |
1 ms |
620 KB |
Output is correct |
9 |
Correct |
3 ms |
1132 KB |
Output is correct |
10 |
Correct |
1 ms |
748 KB |
Output is correct |
11 |
Correct |
1 ms |
1132 KB |
Output is correct |
12 |
Correct |
1 ms |
1132 KB |
Output is correct |
13 |
Correct |
2 ms |
1260 KB |
Output is correct |
14 |
Correct |
1 ms |
1004 KB |
Output is correct |
15 |
Correct |
1 ms |
1132 KB |
Output is correct |
16 |
Correct |
2 ms |
1260 KB |
Output is correct |
17 |
Correct |
1 ms |
876 KB |
Output is correct |
18 |
Correct |
1 ms |
1260 KB |
Output is correct |
19 |
Correct |
2 ms |
1388 KB |
Output is correct |
20 |
Correct |
1 ms |
1132 KB |
Output is correct |
21 |
Correct |
4 ms |
4076 KB |
Output is correct |
22 |
Correct |
265 ms |
126572 KB |
Output is correct |
23 |
Correct |
265 ms |
119404 KB |
Output is correct |
24 |
Correct |
249 ms |
122092 KB |
Output is correct |
25 |
Correct |
270 ms |
123372 KB |
Output is correct |
26 |
Correct |
239 ms |
113004 KB |
Output is correct |
27 |
Correct |
112 ms |
74092 KB |
Output is correct |
28 |
Correct |
144 ms |
87020 KB |
Output is correct |
29 |
Correct |
247 ms |
128128 KB |
Output is correct |
30 |
Correct |
285 ms |
121708 KB |
Output is correct |