#include <bits/stdc++.h>
using namespace std;
#define ll long long int
const ll mod = 1e9+7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,l;
cin >> n >> l;
vector<int> h(n);
for (int i = 0; i < n; i++) cin >> h[i];
sort(h.begin(),h.end());
ll dp[n][n+1][1005][3];
memset(dp,0,sizeof(dp));
dp[0][1][0][2] = 1;
dp[0][1][0][1] = 2;
int v;
for (int i = 0; i < n-1; i++){
for (int j = 1; j < n; j++){
for (int k = 0; k <= l; k++){
for (int t = 0; t < 3; t++){
dp[i][j][k][t] = (dp[i][j][k][t])%mod;
v = (h[i+1]-h[i]) * (2*j-(2-t));
//if (k+v > l && dp[i][j][k][t] > 0) cout << i << " " << j << " " << k << ' ' << t << " " << v << '\n';
if (k + v > l) continue;
// cout << t << " " << v << ' ' << j << ' ' << i << ' ' << k << '\n';
//appending
dp[i+1][j][k+v][t] += dp[i][j][k][t] * (2*j-(2-t));
if (t > 0) dp[i+1][j][k+v][t-1] += dp[i][j][k][t] * (t) * (j+t-2);
if (t == 1 && i == n-2) dp[i+1][j][k+v][t-1] += dp[i][j][k][t];
//combining
dp[i+1][j-1][k+v][t] += dp[i][j][k][t] * (j-1) * (j-2+t);
if (i == n-2 && t == 0) dp[i+1][j-1][k+v][t] += dp[i][j][k][t];
//new cc
dp[i+1][j+1][k+v][t] += dp[i][j][k][t];
if (t != 0) dp[i+1][j+1][k+v][t-1] += dp[i][j][k][t] * (t);
}
}
}
}
if (n == 1) dp[0][1][0][0] = 1;
ll res = 0;
for (int i = 0; i <= l; i++) res = (res + dp[n-1][1][i][0]) % mod;
//for (int i = 0; i <= l; i++) cout << dp[n-1][1][i][0] << " ";
// cout << dp[n-2][1][7][1] << "\n";
// cout << '\n';
cout << res << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
1372 KB |
Output is correct |
5 |
Correct |
1 ms |
1948 KB |
Output is correct |
6 |
Correct |
1 ms |
2140 KB |
Output is correct |
7 |
Correct |
1 ms |
2140 KB |
Output is correct |
8 |
Correct |
1 ms |
2140 KB |
Output is correct |
9 |
Correct |
1 ms |
2140 KB |
Output is correct |
10 |
Correct |
1 ms |
2140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3932 KB |
Output is correct |
2 |
Correct |
3 ms |
5212 KB |
Output is correct |
3 |
Correct |
3 ms |
5212 KB |
Output is correct |
4 |
Correct |
3 ms |
5212 KB |
Output is correct |
5 |
Correct |
2 ms |
5212 KB |
Output is correct |
6 |
Correct |
2 ms |
5212 KB |
Output is correct |
7 |
Correct |
2 ms |
5212 KB |
Output is correct |
8 |
Correct |
2 ms |
5212 KB |
Output is correct |
9 |
Correct |
3 ms |
5212 KB |
Output is correct |
10 |
Correct |
4 ms |
5212 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 |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
1372 KB |
Output is correct |
5 |
Correct |
1 ms |
1948 KB |
Output is correct |
6 |
Correct |
1 ms |
2140 KB |
Output is correct |
7 |
Correct |
1 ms |
2140 KB |
Output is correct |
8 |
Correct |
1 ms |
2140 KB |
Output is correct |
9 |
Correct |
1 ms |
2140 KB |
Output is correct |
10 |
Correct |
1 ms |
2140 KB |
Output is correct |
11 |
Correct |
2 ms |
3932 KB |
Output is correct |
12 |
Correct |
3 ms |
5212 KB |
Output is correct |
13 |
Correct |
3 ms |
5212 KB |
Output is correct |
14 |
Correct |
3 ms |
5212 KB |
Output is correct |
15 |
Correct |
2 ms |
5212 KB |
Output is correct |
16 |
Correct |
2 ms |
5212 KB |
Output is correct |
17 |
Correct |
2 ms |
5212 KB |
Output is correct |
18 |
Correct |
2 ms |
5212 KB |
Output is correct |
19 |
Correct |
3 ms |
5212 KB |
Output is correct |
20 |
Correct |
4 ms |
5212 KB |
Output is correct |
21 |
Correct |
24 ms |
39004 KB |
Output is correct |
22 |
Correct |
111 ms |
145744 KB |
Output is correct |
23 |
Correct |
170 ms |
238672 KB |
Output is correct |
24 |
Correct |
152 ms |
238672 KB |
Output is correct |
25 |
Correct |
165 ms |
238592 KB |
Output is correct |
26 |
Correct |
176 ms |
238676 KB |
Output is correct |
27 |
Correct |
115 ms |
238672 KB |
Output is correct |
28 |
Correct |
121 ms |
238668 KB |
Output is correct |
29 |
Correct |
150 ms |
238788 KB |
Output is correct |
30 |
Correct |
171 ms |
238676 KB |
Output is correct |