#include <bits/stdc++.h>
using namespace std;
const int N = 110;
using ll = long long;
ll dp[N][N][N*10][3],mod = 1000000007;
int n,L,a[N];
int main(void){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> L;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
if(n == 1){ cout << 1; return 0;}
sort(a+1, a+n+1);
dp[1][1][0][0] = 1;
dp[1][1][0][1] = 2;
for(int i = 1; i < n; i++){
for(int j = 1; j <= i; j++){
for(int k = 0; k <= L; k++){
for(int l = 0; l <= 2; l++){
int nk = 0;
if(l < 2){ ///add end point
nk = k+((j)*2-l)*abs(a[i+1]-a[i]);
if(nk <= L){ ///create new component at end point
dp[i+1][j+1][nk][l+1] += dp[i][j][k][l]*(2-l);
dp[i+1][j+1][nk][l+1] %= mod;
}
nk = k+(j*2-l)*abs(a[i+1]-a[i]); ///append i+1th from previous block where i+1th also is end point
if(nk <= L){
dp[i+1][j][nk][l+1] += dp[i][j][k][l]*(2-l);
dp[i+1][j][nk][l+1] %= mod;
}
/*nk = k+((j-1)*2-l-1)*abs(a[i+1]-a[i]); ///merge ?
if(nk <= L){
dp[i+1][j-1][nk][l+1] += dp[i][j][k][l]*(2-l);
dp[i+1][j-1][nk][l+1] %= mod;
}*/
}
nk = k+((j)*2-l)*abs(a[i+1]-a[i]); ///create new component
if(nk <= L){
dp[i+1][j+1][nk][l] += dp[i][j][k][l]*(j+1-l);
dp[i+1][j+1][nk][l] %= mod;
}
nk = k+(j*2-l)*abs(a[i+1]-a[i]); ///append to right most or left most of existing component
if(nk <= L){
dp[i+1][j][nk][l] += dp[i][j][k][l]*(2*j-l);
dp[i+1][j][nk][l] %= mod;
}
nk = k+((j)*2-l)*abs(a[i+1]-a[i]); ///merge component with i+1th
if(nk <= L){
dp[i+1][j-1][nk][l] += dp[i][j][k][l]*(j-1);
dp[i+1][j-1][nk][l] %= mod;
}
}
}
}
}
ll ans = 0;
for(int i = 0; i <= L; i++) ans = (ans+dp[n][1][i][2])%mod;
cout << ans << "\n";
/*for(int i = 1; i <= n; i++){
cout << "I " << i << "\n";
for(int j = 1; j <= i; j++){
cout << "CMP : " << j << "\n";
for(int k = 0; k <= L; k++){
cout << "SUM " << k << " : ";
for(int l = 0; l <= 2; l++){
cout << dp[i][j][k][l] << " ";
}
cout << "\n";
}
}
cout << "\n";
}*/
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
284 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
1100 KB |
Output is correct |
6 |
Correct |
2 ms |
972 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Correct |
1 ms |
580 KB |
Output is correct |
9 |
Correct |
2 ms |
1100 KB |
Output is correct |
10 |
Correct |
1 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
716 KB |
Output is correct |
2 |
Correct |
1 ms |
844 KB |
Output is correct |
3 |
Correct |
1 ms |
844 KB |
Output is correct |
4 |
Correct |
1 ms |
844 KB |
Output is correct |
5 |
Correct |
1 ms |
844 KB |
Output is correct |
6 |
Correct |
1 ms |
972 KB |
Output is correct |
7 |
Correct |
1 ms |
716 KB |
Output is correct |
8 |
Correct |
1 ms |
844 KB |
Output is correct |
9 |
Correct |
1 ms |
972 KB |
Output is correct |
10 |
Correct |
1 ms |
844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
284 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
1100 KB |
Output is correct |
6 |
Correct |
2 ms |
972 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Correct |
1 ms |
580 KB |
Output is correct |
9 |
Correct |
2 ms |
1100 KB |
Output is correct |
10 |
Correct |
1 ms |
588 KB |
Output is correct |
11 |
Correct |
1 ms |
716 KB |
Output is correct |
12 |
Correct |
1 ms |
844 KB |
Output is correct |
13 |
Correct |
1 ms |
844 KB |
Output is correct |
14 |
Correct |
1 ms |
844 KB |
Output is correct |
15 |
Correct |
1 ms |
844 KB |
Output is correct |
16 |
Correct |
1 ms |
972 KB |
Output is correct |
17 |
Correct |
1 ms |
716 KB |
Output is correct |
18 |
Correct |
1 ms |
844 KB |
Output is correct |
19 |
Correct |
1 ms |
972 KB |
Output is correct |
20 |
Correct |
1 ms |
844 KB |
Output is correct |
21 |
Correct |
3 ms |
3532 KB |
Output is correct |
22 |
Correct |
203 ms |
69040 KB |
Output is correct |
23 |
Correct |
249 ms |
83700 KB |
Output is correct |
24 |
Correct |
227 ms |
78912 KB |
Output is correct |
25 |
Correct |
263 ms |
84568 KB |
Output is correct |
26 |
Correct |
222 ms |
76600 KB |
Output is correct |
27 |
Correct |
92 ms |
43212 KB |
Output is correct |
28 |
Correct |
115 ms |
49988 KB |
Output is correct |
29 |
Correct |
209 ms |
76248 KB |
Output is correct |
30 |
Correct |
261 ms |
84520 KB |
Output is correct |