#include "bits/stdc++.h"
using namespace std;
#define ar array
#define int long long
const int mod = 1e9 + 7;
const int N = 105;
int dp[N][N][N * 10][3];
int a[N];
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n, l; cin>>n>>l;
for(int i=0;i<n;i++) cin>>a[i];
sort(a, a+n);
a[n] = N * 10;
if(n == 1){
cout<<1<<"\n";
return 0;
}
dp[1][1][(a[1] - a[0]) * 2][0] = 1;
dp[1][1][a[1] - a[0]][1] = 2;
for(int i=1;i<n;i++){
int dif = a[i+1] - a[i];
for(int j=1;j<=n;j++){
for(int c=0;c<=l;c++){
for(int z=0;z<3;z++){
if(!dp[i][j][c][z]) continue;
if(z < 2 && c + dif * (2 * j - z - 1) <= l){
if(i == n - 1){
dp[i + 1][j][c + dif * (2 * j - z - 1)][z + 1] =
(dp[i + 1][j][c + dif * (2 * j - z - 1)][z + 1] + dp[i][j][c][z] * (2 - z)) % mod;
} else if((z == 1 && j > 1) || z == 0){
dp[i + 1][j][c + dif * (2 * j - z - 1)][z + 1] =
(dp[i + 1][j][c + dif * (2 * j - z - 1)][z + 1] + dp[i][j][c][z] * (j - z) * (2 - z)) % mod;
}
if(c + dif * (2 * j - z + 1) <= l){
dp[i + 1][j + 1][c + dif * (2 * j - z + 1)][z + 1] =
(dp[i + 1][j + 1][c + dif * (2 * j - z + 1)][z + 1] + dp[i][j][c][z] * (2 - z)) % mod;
}
}
// make new component
if(c + dif * (2 * j - z + 2) <= l){
dp[i + 1][j + 1][c + dif * (2 * j - z + 2)][z] =
(dp[i + 1][j + 1][c + dif * (2 * j - z + 2)][z] + dp[i][j][c][z]) % mod;
}
// add to some component
if(c + dif * (2 * j - z) <= l){
dp[i + 1][j][c + dif * (2 * j - z)][z] =
(dp[i + 1][j][c + dif * (2 * j - z)][z] + dp[i][j][c][z] * (2 * j - z)) % mod;
}
if(c + dif * (2 * j - z - 2) <= l && j >= 2 && (z < 2 || i == n - 1 || j > 2)){
if(z == 0){
dp[i + 1][j - 1][c + dif * (2 * j - z - 2)][z] =
(dp[i + 1][j - 1][c + dif * (2 * j - z - 2)][z] + dp[i][j][c][z] * j * (j - 1)) % mod;
}
if(z == 1){
dp[i + 1][j - 1][c + dif * (2 * j - z - 2)][z] =
(dp[i + 1][j - 1][c + dif * (2 * j - z - 2)][z] + dp[i][j][c][z] * (j - 1) * (j - 1)) % mod;
}
if(z == 2){
dp[i + 1][j - 1][c + dif * (2 * j - z - 2)][z] =
(dp[i + 1][j - 1][c + dif * (2 * j - z - 2)][z] + dp[i][j][c][z] * max(1ll, (j - 2) * (j - 1))) % mod;
}
}
}
}
}
}
int res = 0;
for(int i=0;i<=l;i++){
res = (res + dp[n][1][i][2]) % mod;
}
cout<<res<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
420 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
448 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
588 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
572 KB |
Output is correct |
9 |
Correct |
1 ms |
716 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
420 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
448 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
440 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
1 ms |
588 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
588 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
572 KB |
Output is correct |
19 |
Correct |
1 ms |
716 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
2 ms |
1228 KB |
Output is correct |
22 |
Correct |
58 ms |
23876 KB |
Output is correct |
23 |
Correct |
67 ms |
8040 KB |
Output is correct |
24 |
Correct |
60 ms |
11936 KB |
Output is correct |
25 |
Correct |
66 ms |
9272 KB |
Output is correct |
26 |
Correct |
67 ms |
8444 KB |
Output is correct |
27 |
Correct |
30 ms |
9748 KB |
Output is correct |
28 |
Correct |
37 ms |
11984 KB |
Output is correct |
29 |
Correct |
53 ms |
16444 KB |
Output is correct |
30 |
Correct |
68 ms |
9312 KB |
Output is correct |