#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
// #pragma GCC optimize("Ofast")
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 0, n + 1)
#define SZ(x) (int)(x).size()
#define pb push_back
#define pf push_front
#define eb emplace_back
#define f first
#define s second
#define lowbit(x) x&-x
#define ckmin(a, b) a = min(a, b)
#define ckmax(a, b) a = max(a, b)
#define int long long
const int INF = 1e18;
const int maxn = 1000 + 5;
const int N = 1e9 + 7;
ll dp[105][105][2005][3];
signed main(void){
fastio;
int n, L;
cin>>n>>L;
vector<int> a(n);
for(int i = 0; i < n; i++) cin>>a[i];
if(n == 1){
cout<<1<<"\n";
return 0;
}
sort(a.begin(), a.end());
a.pb(a[n - 1]);
dp[0][0][0][0] = 1;
for(int i = 0; i < n; i++){
for(int j = 0; j <= i; j++){
for(int k = 0; k <= L; k++){
for(int l = 0; l <= 2; l++){
dp[i][j][k][l] %= N;
if(k + (2 * j - 2 - l) * (a[i + 1] - a[i]) > L) continue;
if(j) (dp[i + 1][j][k + (2 * j - l) * (a[i + 1] - a[i])][l] += dp[i][j][k][l] * (2 * j - l)) %= N;
(dp[i + 1][j + 1][k + (2 * j + 2 - l) * (a[i + 1] - a[i])][l] += dp[i][j][k][l] * (j + 1 - l)) %= N;
if(j > 1) (dp[i + 1][j - 1][k + (2 * j - 2 - l) * (a[i + 1] - a[i])][l] += dp[i][j][k][l] * (j - 1)) %= N;
if(l != 2){
(dp[i + 1][j][k + (2 * j - (l + 1)) * (a[i + 1] - a[i])][l + 1] += dp[i][j][k][l] * (2 - l)) %= N;
(dp[i + 1][j + 1][k + (2 * j + 2 - (l + 1)) * (a[i + 1] - a[i])][l + 1] += dp[i][j][k][l] * (2 - l)) %= N;
}
// if(dp[i][j][k][l]) cout<<i<<" "<<j<<" "<<k<<" "<<l<<" : "<<dp[i][j][k][l]<<"\n";
}
}
}
}
ll ans = 0;
// for(int i = 0; i <= L; i++) (ans += dp[n - 1][2][i][2]) %= N;
// for(int i = 0; i <= L; i++) (ans += dp[n - 1][1][i][1]) %= N;
for(int i = 0; i <= L; i++) (ans += dp[n][1][i][2]) %= N;
cout<<ans<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
1884 KB |
Output is correct |
6 |
Correct |
2 ms |
1628 KB |
Output is correct |
7 |
Correct |
1 ms |
860 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
1628 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
860 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1160 KB |
Output is correct |
7 |
Correct |
1 ms |
860 KB |
Output is correct |
8 |
Correct |
1 ms |
1112 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
1884 KB |
Output is correct |
6 |
Correct |
2 ms |
1628 KB |
Output is correct |
7 |
Correct |
1 ms |
860 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
1628 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
860 KB |
Output is correct |
12 |
Correct |
1 ms |
1116 KB |
Output is correct |
13 |
Correct |
1 ms |
1116 KB |
Output is correct |
14 |
Correct |
1 ms |
1116 KB |
Output is correct |
15 |
Correct |
1 ms |
1116 KB |
Output is correct |
16 |
Correct |
1 ms |
1160 KB |
Output is correct |
17 |
Correct |
1 ms |
860 KB |
Output is correct |
18 |
Correct |
1 ms |
1112 KB |
Output is correct |
19 |
Correct |
1 ms |
1116 KB |
Output is correct |
20 |
Correct |
1 ms |
1116 KB |
Output is correct |
21 |
Correct |
3 ms |
4968 KB |
Output is correct |
22 |
Correct |
116 ms |
74756 KB |
Output is correct |
23 |
Correct |
174 ms |
143168 KB |
Output is correct |
24 |
Correct |
144 ms |
112972 KB |
Output is correct |
25 |
Correct |
173 ms |
144792 KB |
Output is correct |
26 |
Correct |
153 ms |
126252 KB |
Output is correct |
27 |
Correct |
60 ms |
51692 KB |
Output is correct |
28 |
Correct |
75 ms |
58584 KB |
Output is correct |
29 |
Correct |
125 ms |
91832 KB |
Output is correct |
30 |
Correct |
172 ms |
145160 KB |
Output is correct |