#include <bits/stdc++.h>
using namespace std ;
const int mod = 1e9 + 7 ;
int Add(int x , int y)
{
int z = x + y ;
if(z >= mod)
z -= mod ;
return z ;
}
int Sub(int x , int y)
{
int z = x - y ;
if(z < 0)
z += mod ;
return z ;
}
int Mul(int x , int y)
{
return (1ll * x * y) % mod ;
}
const int MAX = 100 + 10 ;
int arr[MAX] ;
int n , l ;
int dp[MAX][MAX][1004][2][2] ;
int solve(int idx , int cnt , int sum , bool t1 , bool t2)
{
if(idx > 0 && idx < n)
sum += (2*cnt - t1 - t2) * (arr[idx] - arr[idx-1]) ;
if(sum > l)
return 0 ;
if(idx == n)
return (cnt == 1 && t1 && t2) ;
int &ret = dp[idx][cnt][sum][t1][t2] ;
if(ret != -1)
return ret ;
ret = 0 ;
ret = Add(ret , Mul(solve(idx+1 , cnt+1 , sum , t1 , t2) , cnt+1-t1-t2)) ;
if(!t1)
ret = Add(ret , solve(idx+1 , cnt+1 , sum , 1 , t2)) ;
if(!t2)
ret = Add(ret , solve(idx+1 , cnt+1 , sum , t1 , 1)) ;
if(cnt >= 2)
ret = Add(ret , Mul(solve(idx+1 , cnt-1 , sum , t1 , t2) , cnt-1)) ;
if(cnt)
{
ret = Add(ret , Mul(solve(idx+1 , cnt , sum , t1 , t2) , 2 * cnt - t1 - t2)) ;
if(!t1)
ret = Add(ret , solve(idx+1 , cnt , sum , 1 , t2)) ;
if(!t2)
ret = Add(ret , solve(idx+1 , cnt , sum , t1 , 1)) ;
}
return ret ;
}
int main()
{
memset(dp , -1 , sizeof(dp)) ;
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
cin>>n>>l ;
for(int i = 0 ; i < n ; ++i)
cin>>arr[i] ;
sort(arr , arr + n) ;
if(n == 1)
return cout<<1<<"\n" , 0 ;
return cout<<solve(0 , 0 , 0 , 0 , 0)<<"\n" , 0 ;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
99 ms |
190492 KB |
Output is correct |
2 |
Correct |
104 ms |
190496 KB |
Output is correct |
3 |
Correct |
106 ms |
190444 KB |
Output is correct |
4 |
Correct |
94 ms |
190436 KB |
Output is correct |
5 |
Correct |
100 ms |
190388 KB |
Output is correct |
6 |
Correct |
102 ms |
190424 KB |
Output is correct |
7 |
Correct |
106 ms |
190488 KB |
Output is correct |
8 |
Correct |
93 ms |
190448 KB |
Output is correct |
9 |
Correct |
113 ms |
190388 KB |
Output is correct |
10 |
Correct |
105 ms |
190428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
99 ms |
190428 KB |
Output is correct |
2 |
Correct |
90 ms |
190444 KB |
Output is correct |
3 |
Correct |
98 ms |
190432 KB |
Output is correct |
4 |
Correct |
77 ms |
190428 KB |
Output is correct |
5 |
Correct |
100 ms |
190492 KB |
Output is correct |
6 |
Correct |
108 ms |
190472 KB |
Output is correct |
7 |
Correct |
104 ms |
190392 KB |
Output is correct |
8 |
Correct |
113 ms |
190492 KB |
Output is correct |
9 |
Correct |
96 ms |
190520 KB |
Output is correct |
10 |
Correct |
92 ms |
190416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
99 ms |
190492 KB |
Output is correct |
2 |
Correct |
104 ms |
190496 KB |
Output is correct |
3 |
Correct |
106 ms |
190444 KB |
Output is correct |
4 |
Correct |
94 ms |
190436 KB |
Output is correct |
5 |
Correct |
100 ms |
190388 KB |
Output is correct |
6 |
Correct |
102 ms |
190424 KB |
Output is correct |
7 |
Correct |
106 ms |
190488 KB |
Output is correct |
8 |
Correct |
93 ms |
190448 KB |
Output is correct |
9 |
Correct |
113 ms |
190388 KB |
Output is correct |
10 |
Correct |
105 ms |
190428 KB |
Output is correct |
11 |
Correct |
99 ms |
190428 KB |
Output is correct |
12 |
Correct |
90 ms |
190444 KB |
Output is correct |
13 |
Correct |
98 ms |
190432 KB |
Output is correct |
14 |
Correct |
77 ms |
190428 KB |
Output is correct |
15 |
Correct |
100 ms |
190492 KB |
Output is correct |
16 |
Correct |
108 ms |
190472 KB |
Output is correct |
17 |
Correct |
104 ms |
190392 KB |
Output is correct |
18 |
Correct |
113 ms |
190492 KB |
Output is correct |
19 |
Correct |
96 ms |
190520 KB |
Output is correct |
20 |
Correct |
92 ms |
190416 KB |
Output is correct |
21 |
Correct |
108 ms |
190492 KB |
Output is correct |
22 |
Correct |
319 ms |
190500 KB |
Output is correct |
23 |
Correct |
146 ms |
190412 KB |
Output is correct |
24 |
Correct |
183 ms |
190528 KB |
Output is correct |
25 |
Correct |
209 ms |
190392 KB |
Output is correct |
26 |
Correct |
192 ms |
190500 KB |
Output is correct |
27 |
Correct |
160 ms |
190528 KB |
Output is correct |
28 |
Correct |
164 ms |
190500 KB |
Output is correct |
29 |
Correct |
220 ms |
190520 KB |
Output is correct |
30 |
Correct |
232 ms |
190496 KB |
Output is correct |