#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
typedef long long ll;
const ll mod = 1e9 + 7;
ll n, mx, dp[105][105][1005][5], h[101];
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> mx;
for(int i = 1; i <= n; i++) cin >> h[i];
if(n == 1){
cout << "1"; return 0;
}
sort(h + 1, h + n + 1);
dp[0][0][0][0] = 1; h[n + 1] = 10000;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= i; j++)
for(int kk = 0; kk <= mx; kk++)
for(int l = 0; l < 3; l++){
int d = (2 * j - l) * (h[i + 1] - h[i]);
int k = kk + d;
if(k > mx) continue;
if(j > l) dp[i][j][k][l] += (j - l) * dp[i - 1][j - 1][kk][l];
dp[i][j][k][l] += (2 * j - l) * dp[i - 1][j][kk][l];
dp[i][j][k][l] += j * dp[i - 1][j + 1][kk][l];
if(l) {
dp[i][j][k][l] += (3 - l) * dp[i - 1][j - 1][kk][l - 1];
if(i == 2 && j == 1 && k == 5 && l == 1){
//cout << i << ' ' << j << ' ' << kk << ' ' << l - 1 << ' ' << dp[i][j][kk][l - 1] << '\n';
}
dp[i][j][k][l] += (3 - l) * dp[i - 1][j][kk][l - 1];
}
dp[i][j][k][l] %= mod;
//cout << i << ' ' << j << ' ' << k << ' ' << l << ' ' << dp[i][j][k][l] << '\n';
}
ll ans = 0;
for(int i = 0; i <= mx; i++) ans += dp[n][1][i][2], ans %= mod;
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
352 KB |
Output is correct |
5 |
Correct |
2 ms |
988 KB |
Output is correct |
6 |
Correct |
1 ms |
864 KB |
Output is correct |
7 |
Correct |
1 ms |
480 KB |
Output is correct |
8 |
Correct |
1 ms |
480 KB |
Output is correct |
9 |
Correct |
2 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
768 KB |
Output is correct |
2 |
Correct |
2 ms |
900 KB |
Output is correct |
3 |
Correct |
1 ms |
852 KB |
Output is correct |
4 |
Correct |
2 ms |
748 KB |
Output is correct |
5 |
Correct |
2 ms |
856 KB |
Output is correct |
6 |
Correct |
2 ms |
992 KB |
Output is correct |
7 |
Correct |
1 ms |
768 KB |
Output is correct |
8 |
Correct |
1 ms |
864 KB |
Output is correct |
9 |
Correct |
2 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
352 KB |
Output is correct |
5 |
Correct |
2 ms |
988 KB |
Output is correct |
6 |
Correct |
1 ms |
864 KB |
Output is correct |
7 |
Correct |
1 ms |
480 KB |
Output is correct |
8 |
Correct |
1 ms |
480 KB |
Output is correct |
9 |
Correct |
2 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
768 KB |
Output is correct |
12 |
Correct |
2 ms |
900 KB |
Output is correct |
13 |
Correct |
1 ms |
852 KB |
Output is correct |
14 |
Correct |
2 ms |
748 KB |
Output is correct |
15 |
Correct |
2 ms |
856 KB |
Output is correct |
16 |
Correct |
2 ms |
992 KB |
Output is correct |
17 |
Correct |
1 ms |
768 KB |
Output is correct |
18 |
Correct |
1 ms |
864 KB |
Output is correct |
19 |
Correct |
2 ms |
980 KB |
Output is correct |
20 |
Correct |
1 ms |
768 KB |
Output is correct |
21 |
Correct |
3 ms |
3296 KB |
Output is correct |
22 |
Correct |
141 ms |
100828 KB |
Output is correct |
23 |
Correct |
159 ms |
119240 KB |
Output is correct |
24 |
Correct |
129 ms |
112732 KB |
Output is correct |
25 |
Correct |
155 ms |
120756 KB |
Output is correct |
26 |
Correct |
138 ms |
108580 KB |
Output is correct |
27 |
Correct |
70 ms |
55344 KB |
Output is correct |
28 |
Correct |
98 ms |
66144 KB |
Output is correct |
29 |
Correct |
155 ms |
107820 KB |
Output is correct |
30 |
Correct |
198 ms |
121004 KB |
Output is correct |