#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const ll md = 1e9+7;
const int lim = 1005;
ll dp[100][101][lim][3];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
for(int i = 0; i < 100; i++) for(int j = 0; j <= 100; j++)
for(int k = 0; k < lim; k++) for(int l = 0; l < 3; l++) dp[i][j][k][l] = 0;
int n, L; cin >> n >> L;
vector<int> A(n);
for(int &x: A) cin >> x;
sort(A.begin(), A.end());
auto d = [&](int i, int j, int m){
return (2*j-m)*(A[i]-A[i-1]);
};
dp[0][1][0][0] = 1;
dp[0][1][0][1] = 2;
if(n == 1) dp[0][1][0][2] = 1;
for(int i = 1; i < n; i++) for(int j = 1; j <= i+1; j++)
for(int c = 0; c < lim; c++) for(int m = 0; m <= 2; m++){
//-
if(c-d(i,j-1,m) >= 0 && j > 1)
dp[i][j][c][m]+=dp[i-1][j-1][c-d(i,j-1,m)][m], dp[i][j][c][m]%=md;
//:-
if(c-d(i,j-1,m-1) >= 0 && j > 1 && m > 0){
if(j == 1 && i == n-1 && m == 2)
dp[i][j][c][m]+=dp[i-1][j-1][c-d(i,j-1,m-1)][m-1], dp[i][j][c][m]%=md;
else if(j != 1)
dp[i][j][c][m]+=(dp[i-1][j-1][c-d(i,j-1,m-1)][m-1]*(3-m))%md, dp[i][j][c][m]%=md;
}
//---- + - = -----
if(c-d(i,j,m) >= 0)
dp[i][j][c][m]+=(dp[i-1][j][c-d(i,j,m)][m]*(2*j-m))%md, dp[i][j][c][m]%=md;
//---- + -: = -----:
if(c-d(i,j,m-1) >= 0 && m > 0){
if(i == n-1 && j == 1 && m == 2)
dp[i][j][c][m]+=dp[i-1][j][c-d(i,j,m-1)][m-1], dp[i][j][c][m]%=md;
else if(m == 1)
dp[i][j][c][m]+=(dp[i-1][j][c-d(i,j,m-1)][m-1]*2*j)%md, dp[i][j][c][m]%=md;
else if(j != 1)
dp[i][j][c][m]+=(dp[i-1][j][c-d(i,j,m-1)][m-1]*(j-1))%md, dp[i][j][c][m]%=md;
}
//---- + - + ---- = ---------
if(c-d(i,j+1,m) >= 0 && j+1 <= i){
if(i == n-1 && j == 1 && m == 2)
dp[i][j][c][m]+=dp[i-1][j+1][c-d(i,j+1,m)][m], dp[i][j][c][m]%=md;
else if(m == 0)
dp[i][j][c][m]+=(dp[i-1][j+1][c-d(i,j+1,m)][m]*j*(j+1))%md, dp[i][j][c][m]%=md;
else if(m == 1)
dp[i][j][c][m]+=(dp[i-1][j+1][c-d(i,j+1,m)][m]*j*j)%md, dp[i][j][c][m]%=md;
else if(j != 1)
dp[i][j][c][m]+=(dp[i-1][j+1][c-d(i,j+1,m)][m]*j*(j-1))%md, dp[i][j][c][m]%=md;
}
}
ll ans = 0;
for(int i = 0; i <= L; i++) ans+=dp[n-1][1][i][2], ans%=md;
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
114 ms |
238584 KB |
Output is correct |
2 |
Correct |
95 ms |
238592 KB |
Output is correct |
3 |
Correct |
98 ms |
238552 KB |
Output is correct |
4 |
Correct |
104 ms |
238608 KB |
Output is correct |
5 |
Correct |
98 ms |
238608 KB |
Output is correct |
6 |
Correct |
101 ms |
238660 KB |
Output is correct |
7 |
Correct |
103 ms |
238596 KB |
Output is correct |
8 |
Correct |
95 ms |
238672 KB |
Output is correct |
9 |
Correct |
93 ms |
238580 KB |
Output is correct |
10 |
Correct |
98 ms |
238556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
238612 KB |
Output is correct |
2 |
Correct |
107 ms |
238652 KB |
Output is correct |
3 |
Correct |
103 ms |
238636 KB |
Output is correct |
4 |
Correct |
115 ms |
238540 KB |
Output is correct |
5 |
Correct |
105 ms |
238668 KB |
Output is correct |
6 |
Correct |
102 ms |
238608 KB |
Output is correct |
7 |
Correct |
120 ms |
238584 KB |
Output is correct |
8 |
Correct |
106 ms |
238572 KB |
Output is correct |
9 |
Correct |
101 ms |
238604 KB |
Output is correct |
10 |
Correct |
108 ms |
238568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
114 ms |
238584 KB |
Output is correct |
2 |
Correct |
95 ms |
238592 KB |
Output is correct |
3 |
Correct |
98 ms |
238552 KB |
Output is correct |
4 |
Correct |
104 ms |
238608 KB |
Output is correct |
5 |
Correct |
98 ms |
238608 KB |
Output is correct |
6 |
Correct |
101 ms |
238660 KB |
Output is correct |
7 |
Correct |
103 ms |
238596 KB |
Output is correct |
8 |
Correct |
95 ms |
238672 KB |
Output is correct |
9 |
Correct |
93 ms |
238580 KB |
Output is correct |
10 |
Correct |
98 ms |
238556 KB |
Output is correct |
11 |
Correct |
100 ms |
238612 KB |
Output is correct |
12 |
Correct |
107 ms |
238652 KB |
Output is correct |
13 |
Correct |
103 ms |
238636 KB |
Output is correct |
14 |
Correct |
115 ms |
238540 KB |
Output is correct |
15 |
Correct |
105 ms |
238668 KB |
Output is correct |
16 |
Correct |
102 ms |
238608 KB |
Output is correct |
17 |
Correct |
120 ms |
238584 KB |
Output is correct |
18 |
Correct |
106 ms |
238572 KB |
Output is correct |
19 |
Correct |
101 ms |
238604 KB |
Output is correct |
20 |
Correct |
108 ms |
238568 KB |
Output is correct |
21 |
Correct |
155 ms |
238592 KB |
Output is correct |
22 |
Correct |
287 ms |
238676 KB |
Output is correct |
23 |
Correct |
300 ms |
238668 KB |
Output is correct |
24 |
Correct |
317 ms |
238672 KB |
Output is correct |
25 |
Correct |
289 ms |
238672 KB |
Output is correct |
26 |
Correct |
292 ms |
238676 KB |
Output is correct |
27 |
Correct |
369 ms |
238672 KB |
Output is correct |
28 |
Correct |
368 ms |
238668 KB |
Output is correct |
29 |
Correct |
344 ms |
238676 KB |
Output is correct |
30 |
Correct |
256 ms |
238672 KB |
Output is correct |