#include<bits/stdc++.h>
#ifdef LOCAL
#include "Essentials/algo/debug.h"
#else
#define debug(...) 69
#define debugArr(...) 69
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N = 100 + 23;
const int M = 1000 + 23;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
#define F first
#define S second
#define pb push_back
#define kill(x) cout<<x<<endl, exit(0);
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define lc (v << 1)
#define rc ((v<<1) |1)
#define int ll
void ok(int &x) {
if(x < 0) x += mod*mod;
x %= mod;
}
int n,l;
int a[N];
int dp[N][N][M][3];
int32_t main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin>>n>>l;
for(int i = 1;i <= n ; i ++) cin>>a[i];
if(n == 1) kill(1);
sort(a+1,a+n+1);
a[n+1] = M*M;
dp[0][0][0][0] = 1;
for(int i = 1; i<= n; i ++) for(int j=1; j <= i ; j ++) for(int k = 0 ; k <= l;k ++) for(int m = 0; m < 3; m ++) {
int cost = (2*j-m)*(a[i+1]-a[i]);
if(k-cost < 0 || i + j+ 1-m > n) continue;
// halat aval-> componente jadid:
ok(dp[i][j][k][m] += dp[i-1][j-1][k-cost][m]);
// halat dovom -> componente jadid az yeki az do sar
if(m)
ok(dp[i][j][k][m] += (3-m)*dp[i-1][j-1][k-cost][m-1]);
// halat sevom -> ezafe be tahe component
ok(dp[i][j][k][m] += (2 *j - m) * dp[i-1][j][k-cost][m]);
// halat 4:
if(m == 1) {
ok(dp[i][j][k][m] += 2*j * dp[i-1][j][k-cost][m-1]);
} else if(m == 2) {
if(i == n) {
ok(dp[i][j][k][m] += dp[i-1][j][k-cost][m-1]);
} else {
ok(dp[i][j][k][m] += (j-1)*dp[i-1][j][k-cost][m-1]);
}
}
// halat 5:
if(m == 2 && i == n) {
ok(dp[i][j][k][m] += dp[i-1][j+1][k-cost][m]);
} else if(m == 2) {
ok(dp[i][j][k][m] += j*(j-1)%mod*dp[i-1][j+1][k-cost][m]);
} else if(m == 1) {
ok(dp[i][j][k][m] += j*j%mod*dp[i-1][j+1][k-cost][m]);
} else {
ok(dp[i][j][k][m] += j*(j+1)%mod*dp[i-1][j+1][k-cost][m]);
}
}
int ans =0;
for(int i = 0 ; i <= l; i ++) ok(ans += dp[n][1][i][2]);
cout<<ans << '\n';
return 0;
}
// Jumpsuit, Jumpsuit cover me!
// Jumpsuit, Jumpsuit cover me!
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
860 KB |
Output is correct |
6 |
Correct |
1 ms |
860 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
860 KB |
Output is correct |
6 |
Correct |
1 ms |
860 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
604 KB |
Output is correct |
21 |
Correct |
2 ms |
2396 KB |
Output is correct |
22 |
Correct |
50 ms |
35816 KB |
Output is correct |
23 |
Correct |
70 ms |
48212 KB |
Output is correct |
24 |
Correct |
64 ms |
46928 KB |
Output is correct |
25 |
Correct |
72 ms |
51280 KB |
Output is correct |
26 |
Correct |
63 ms |
46248 KB |
Output is correct |
27 |
Correct |
25 ms |
23632 KB |
Output is correct |
28 |
Correct |
29 ms |
26972 KB |
Output is correct |
29 |
Correct |
51 ms |
41300 KB |
Output is correct |
30 |
Correct |
73 ms |
51536 KB |
Output is correct |