#include "bits/stdc++.h"
using namespace std;
const int mod = 1e9 + 7;
const int MAX = 1e3 + 5;
void add(int& a, int b){
a += b;
if(a >= mod) a -= mod;
}
int mul(int a, int b){
return 1LL * a * b % mod;
}
int n, L, a[MAX], dp[101][101][1001][3];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> L;
for(int i = 1; i <= n; ++i){
cin >> a[i];
}
if(n == 1){
cout << 1 << '\n';
return 0;
}
sort(a + 1, a + n + 1);
dp[1][1][0][0] = 1;
dp[1][1][0][1] = 2;
for(int i = 1; i < n; ++i){
for(int j = 1; j <= i; ++j){
for(int k = 0; k <= L; ++k){
for(int l = 0; l < 3; ++l){
int& ret = dp[i][j][k][l];
if(!ret) continue;
int sum = k + (2 * j - l) * (a[i + 1] - a[i]);
if((2 * j - l) < 0 || sum > L) continue;
add(dp[i + 1][j + 1][sum][l], mul(ret, j + 1 - l));
if(l < 2) add(dp[i + 1][j + 1][sum][l + 1], mul(ret, 2 - l));
add(dp[i + 1][j][sum][l], mul(ret, 2 * j - l));
if(l < 2) add(dp[i + 1][j][sum][l + 1], mul(ret, 2 - l));
if(j > 0) add(dp[i + 1][j - 1][sum][l], mul(ret, j - 1));
}
}
}
}
int res = 0;
for(int i = 0; i <= L; ++i){
add(res, dp[n][1][i][2]);
}
cout << res << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
728 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
728 KB |
Output is correct |
3 |
Correct |
1 ms |
860 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
860 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
860 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
728 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
728 KB |
Output is correct |
13 |
Correct |
1 ms |
860 KB |
Output is correct |
14 |
Correct |
1 ms |
724 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
860 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
860 KB |
Output is correct |
19 |
Correct |
1 ms |
860 KB |
Output is correct |
20 |
Correct |
0 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
1372 KB |
Output is correct |
22 |
Correct |
47 ms |
16780 KB |
Output is correct |
23 |
Correct |
22 ms |
7004 KB |
Output is correct |
24 |
Correct |
25 ms |
10068 KB |
Output is correct |
25 |
Correct |
25 ms |
7772 KB |
Output is correct |
26 |
Correct |
21 ms |
7548 KB |
Output is correct |
27 |
Correct |
15 ms |
8796 KB |
Output is correct |
28 |
Correct |
19 ms |
10524 KB |
Output is correct |
29 |
Correct |
34 ms |
12884 KB |
Output is correct |
30 |
Correct |
29 ms |
8000 KB |
Output is correct |