#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
using ll = long long ;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
int const nmax = 100;
int const lmax = 1000;
int const modulo = 1000000007;
int dp[5 + nmax][5 + lmax][2][2];
int dp2[5 + nmax][5 + lmax][2][2];
int v[1 + nmax];
void norm(int &aux) {
if(modulo <= aux)
aux -= modulo;
}
int main() {
int n, target;
std::cin >> n >> target;
for(int i = 1;i <= n; i++)
std::cin >> v[i];
std::sort(v + 1, v + n + 1);
for(int h = 0; h < 2; h++)
for(int h2 = 0; h2 < 2; h2++)
dp[0][0][h][h2] = 1;
for(int phase = 2; phase <= n; phase++) {
for(int i = 0; i <= n; i++)
for(int j = 0; j <= target; j++)
for(int h = 0; h < 2; h++)
for(int h2 = 0; h2 < 2; h2++) {
int bonus = (i * 2 + h + h2) * (v[phase] - v[phase - 1]);
if(j + bonus <= target) {
dp2[i][j + bonus][h][h2] += dp[i][j][h][h2];
norm(dp2[i][j + bonus][h][h2]);
}
}
for(int i = 0; i <= n; i++)
for(int j = 0; j <= target; j++)
for(int h = 0; h < 2; h++)
for(int h2 = 0; h2 < 2; h2++) {
dp[i][j][h][h2] = dp2[i][j][h][h2];
dp2[i][j][h][h2] = 0;
}
for(int i = 0; i <= n; i++)
for(int j = 0; j <= target; j++)
for(int h = 0; h < 2; h++)
for(int h2 = 0; h2 < 2; h2++) {
if(0 < i) {
dp2[i + 1][j][h][h2] += 1LL * dp[i][j][h][h2] * i % modulo;
norm(dp2[i + 1][j][h][h2]);
dp2[i][j][h][h2] += 1LL * dp[i][j][h][h2] * i * 2 % modulo;
norm(dp2[i][j][h][h2]);
dp2[i - 1][j][h][h2] += 1LL * dp[i][j][h][h2] * i % modulo;
norm(dp2[i - 1][j][h][h2]);
}
if(h == 1) {
dp2[i][j][h][h2] += 1LL * dp[i][j][h][h2] % modulo;
norm(dp2[i][j][h][h2]);
dp2[i][j][0][h2] += 1LL * dp[i][j][h][h2] % modulo;
norm(dp2[i][j][0][h2]);
dp2[i + 1][j][h][h2] += 1LL * dp[i][j][h][h2] % modulo;
norm(dp2[i + 1][j][h][h2]);
dp2[i + 1][j][0][h2] += 1LL * dp[i][j][h][h2] % modulo;
norm(dp2[i + 1][j][0][h2]);
}
if(h2 == 1) {
dp2[i][j][h][h2] += 1LL * dp[i][j][h][h2] % modulo;
norm(dp2[i][j][h][h2]);
dp2[i][j][h][0] += 1LL * dp[i][j][h][h2] % modulo;
norm(dp2[i][j][h][0]);
dp2[i + 1][j][h][h2] += 1LL * dp[i][j][h][h2] % modulo;
norm(dp2[i + 1][j][h][h2]);
dp2[i + 1][j][h][0] += 1LL * dp[i][j][h][h2] % modulo;
norm(dp2[i + 1][j][h][0]);
}
}
for(int i = 0; i <= n; i++)
for(int j = 0; j <= target; j++)
for(int h = 0; h < 2; h++)
for(int h2 = 0; h2 < 2; h2++) {
dp[i][j][h][h2] = dp2[i][j][h][h2];
dp2[i][j][h][h2] = 0;
}
}
int result = 0;
for(int j = 0; j <= target; j++) {
result += dp[0][j][0][0];
if(modulo <= result)
result -= modulo;
}
std::cout << result;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
4 ms |
620 KB |
Output is correct |
6 |
Correct |
4 ms |
620 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
4 ms |
620 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
2 ms |
524 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
2 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
2 ms |
492 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
4 ms |
620 KB |
Output is correct |
6 |
Correct |
4 ms |
620 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
4 ms |
620 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
2 ms |
524 KB |
Output is correct |
13 |
Correct |
1 ms |
492 KB |
Output is correct |
14 |
Correct |
2 ms |
492 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
2 ms |
492 KB |
Output is correct |
17 |
Correct |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
2 ms |
492 KB |
Output is correct |
20 |
Correct |
2 ms |
492 KB |
Output is correct |
21 |
Correct |
5 ms |
748 KB |
Output is correct |
22 |
Correct |
336 ms |
2924 KB |
Output is correct |
23 |
Correct |
661 ms |
3692 KB |
Output is correct |
24 |
Correct |
519 ms |
3540 KB |
Output is correct |
25 |
Correct |
654 ms |
3564 KB |
Output is correct |
26 |
Correct |
554 ms |
3692 KB |
Output is correct |
27 |
Correct |
167 ms |
2028 KB |
Output is correct |
28 |
Correct |
212 ms |
2028 KB |
Output is correct |
29 |
Correct |
379 ms |
3072 KB |
Output is correct |
30 |
Correct |
678 ms |
3692 KB |
Output is correct |