#include <bits/stdc++.h>
using namespace std;
int n, l, x;
const int MOD = 1e9 + 7;
int nCr[30500][500];
int dp[51][100001][51];
int add (int a, int b) {
a += b; if (a >= MOD) a -= MOD;
return a;
}
int sub (int a, int b) {
a -= b; if (a < 0) a += MOD;
return a;
}
int mul (int a, int b) {
return (a * 1ll * b) % MOD;
}
int arr[51];
int main () {
cin >> n >> l;
for (int i = 0; i < 30500; i++) {
for (int j = 0; j <= min(499, i); j++) {
if (j == 0 || j == i) {
nCr[i][j] = 1;
} else {
nCr[i][j] = add(nCr[i - 1][j], nCr[i - 1][j - 1]);
}
}
}
for (int i = 1; i <= n; i++) cin >> arr[i];
sort(arr + 1, arr + n + 1);
dp[0][0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= l; j++) {
for (int k = 1; k <= i; k++) {
dp[i][j][k] = 0;
if (2 * arr[i] - 1 <= j) dp[i][j][k] = add(dp[i][j][k], mul(mul(k + 1, k), dp[i - 1][j - 2 * arr[i] + 1][k + 1]));
dp[i][j][k] = add(dp[i][j][k], dp[i - 1][j - 1][k - 1]);
if (arr[i] <= j) dp[i][j][k] = add(dp[i][j][k], mul(2 * k, dp[i - 1][j - arr[i]][k]));
//cout << i << " " << j << " " << k << ": " << dp[i][j][k] << '\n';
}
}
}
//for (int i = 1; i <= l; i++) cout << dp[n][i][1] << '\n';
int sum = 0;
for (int i = 1; i <= l; i++) sum = add(sum, mul(dp[n][i][1], nCr[n - i + l][n]));
cout << sum << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
112 ms |
257104 KB |
Output is correct |
2 |
Correct |
31 ms |
162632 KB |
Output is correct |
3 |
Correct |
39 ms |
99044 KB |
Output is correct |
4 |
Correct |
34 ms |
76380 KB |
Output is correct |
5 |
Correct |
43 ms |
113476 KB |
Output is correct |
6 |
Correct |
49 ms |
164624 KB |
Output is correct |
7 |
Correct |
54 ms |
203788 KB |
Output is correct |
8 |
Correct |
24 ms |
62036 KB |
Output is correct |
9 |
Correct |
38 ms |
160500 KB |
Output is correct |
10 |
Correct |
22 ms |
62176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
99164 KB |
Output is correct |
2 |
Correct |
23 ms |
68316 KB |
Output is correct |
3 |
Correct |
28 ms |
98908 KB |
Output is correct |
4 |
Correct |
25 ms |
74508 KB |
Output is correct |
5 |
Correct |
28 ms |
98908 KB |
Output is correct |
6 |
Correct |
24 ms |
76556 KB |
Output is correct |
7 |
Correct |
28 ms |
98900 KB |
Output is correct |
8 |
Correct |
26 ms |
80468 KB |
Output is correct |
9 |
Correct |
24 ms |
76380 KB |
Output is correct |
10 |
Correct |
23 ms |
64092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
121712 KB |
Output is correct |
2 |
Correct |
27 ms |
101188 KB |
Output is correct |
3 |
Correct |
30 ms |
121592 KB |
Output is correct |
4 |
Correct |
26 ms |
103200 KB |
Output is correct |
5 |
Correct |
28 ms |
121684 KB |
Output is correct |
6 |
Correct |
26 ms |
98896 KB |
Output is correct |
7 |
Correct |
30 ms |
121684 KB |
Output is correct |
8 |
Correct |
25 ms |
80640 KB |
Output is correct |
9 |
Correct |
27 ms |
103160 KB |
Output is correct |
10 |
Correct |
25 ms |
80580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
112 ms |
257104 KB |
Output is correct |
2 |
Correct |
31 ms |
162632 KB |
Output is correct |
3 |
Correct |
39 ms |
99044 KB |
Output is correct |
4 |
Correct |
34 ms |
76380 KB |
Output is correct |
5 |
Correct |
43 ms |
113476 KB |
Output is correct |
6 |
Correct |
49 ms |
164624 KB |
Output is correct |
7 |
Correct |
54 ms |
203788 KB |
Output is correct |
8 |
Correct |
24 ms |
62036 KB |
Output is correct |
9 |
Correct |
38 ms |
160500 KB |
Output is correct |
10 |
Correct |
22 ms |
62176 KB |
Output is correct |
11 |
Correct |
35 ms |
99164 KB |
Output is correct |
12 |
Correct |
23 ms |
68316 KB |
Output is correct |
13 |
Correct |
28 ms |
98908 KB |
Output is correct |
14 |
Correct |
25 ms |
74508 KB |
Output is correct |
15 |
Correct |
28 ms |
98908 KB |
Output is correct |
16 |
Correct |
24 ms |
76556 KB |
Output is correct |
17 |
Correct |
28 ms |
98900 KB |
Output is correct |
18 |
Correct |
26 ms |
80468 KB |
Output is correct |
19 |
Correct |
24 ms |
76380 KB |
Output is correct |
20 |
Correct |
23 ms |
64092 KB |
Output is correct |
21 |
Correct |
29 ms |
121712 KB |
Output is correct |
22 |
Correct |
27 ms |
101188 KB |
Output is correct |
23 |
Correct |
30 ms |
121592 KB |
Output is correct |
24 |
Correct |
26 ms |
103200 KB |
Output is correct |
25 |
Correct |
28 ms |
121684 KB |
Output is correct |
26 |
Correct |
26 ms |
98896 KB |
Output is correct |
27 |
Correct |
30 ms |
121684 KB |
Output is correct |
28 |
Correct |
25 ms |
80640 KB |
Output is correct |
29 |
Correct |
27 ms |
103160 KB |
Output is correct |
30 |
Correct |
25 ms |
80580 KB |
Output is correct |
31 |
Correct |
113 ms |
257108 KB |
Output is correct |
32 |
Correct |
73 ms |
216036 KB |
Output is correct |
33 |
Correct |
106 ms |
257052 KB |
Output is correct |
34 |
Correct |
42 ms |
152404 KB |
Output is correct |
35 |
Correct |
104 ms |
256996 KB |
Output is correct |
36 |
Correct |
31 ms |
107356 KB |
Output is correct |
37 |
Correct |
113 ms |
257108 KB |
Output is correct |
38 |
Correct |
46 ms |
168788 KB |
Output is correct |
39 |
Correct |
97 ms |
257096 KB |
Output is correct |
40 |
Correct |
49 ms |
166732 KB |
Output is correct |
41 |
Correct |
103 ms |
257040 KB |
Output is correct |
42 |
Correct |
24 ms |
78428 KB |
Output is correct |
43 |
Correct |
99 ms |
256912 KB |
Output is correct |
44 |
Correct |
44 ms |
123732 KB |
Output is correct |
45 |
Correct |
99 ms |
257092 KB |
Output is correct |
46 |
Correct |
28 ms |
68324 KB |
Output is correct |
47 |
Correct |
40 ms |
170836 KB |
Output is correct |
48 |
Correct |
34 ms |
152400 KB |
Output is correct |
49 |
Correct |
25 ms |
84564 KB |
Output is correct |
50 |
Correct |
24 ms |
82524 KB |
Output is correct |