#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 |
74 ms |
190468 KB |
Output is correct |
2 |
Correct |
72 ms |
190448 KB |
Output is correct |
3 |
Correct |
77 ms |
190472 KB |
Output is correct |
4 |
Correct |
75 ms |
190500 KB |
Output is correct |
5 |
Correct |
74 ms |
190504 KB |
Output is correct |
6 |
Correct |
74 ms |
190456 KB |
Output is correct |
7 |
Correct |
78 ms |
190560 KB |
Output is correct |
8 |
Correct |
76 ms |
190448 KB |
Output is correct |
9 |
Correct |
78 ms |
190460 KB |
Output is correct |
10 |
Correct |
71 ms |
190380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
72 ms |
190412 KB |
Output is correct |
2 |
Correct |
86 ms |
190408 KB |
Output is correct |
3 |
Correct |
74 ms |
190496 KB |
Output is correct |
4 |
Correct |
73 ms |
190420 KB |
Output is correct |
5 |
Correct |
72 ms |
190500 KB |
Output is correct |
6 |
Correct |
74 ms |
190456 KB |
Output is correct |
7 |
Correct |
76 ms |
190412 KB |
Output is correct |
8 |
Correct |
79 ms |
190436 KB |
Output is correct |
9 |
Correct |
71 ms |
190376 KB |
Output is correct |
10 |
Correct |
71 ms |
190404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
190468 KB |
Output is correct |
2 |
Correct |
72 ms |
190448 KB |
Output is correct |
3 |
Correct |
77 ms |
190472 KB |
Output is correct |
4 |
Correct |
75 ms |
190500 KB |
Output is correct |
5 |
Correct |
74 ms |
190504 KB |
Output is correct |
6 |
Correct |
74 ms |
190456 KB |
Output is correct |
7 |
Correct |
78 ms |
190560 KB |
Output is correct |
8 |
Correct |
76 ms |
190448 KB |
Output is correct |
9 |
Correct |
78 ms |
190460 KB |
Output is correct |
10 |
Correct |
71 ms |
190380 KB |
Output is correct |
11 |
Correct |
72 ms |
190412 KB |
Output is correct |
12 |
Correct |
86 ms |
190408 KB |
Output is correct |
13 |
Correct |
74 ms |
190496 KB |
Output is correct |
14 |
Correct |
73 ms |
190420 KB |
Output is correct |
15 |
Correct |
72 ms |
190500 KB |
Output is correct |
16 |
Correct |
74 ms |
190456 KB |
Output is correct |
17 |
Correct |
76 ms |
190412 KB |
Output is correct |
18 |
Correct |
79 ms |
190436 KB |
Output is correct |
19 |
Correct |
71 ms |
190376 KB |
Output is correct |
20 |
Correct |
71 ms |
190404 KB |
Output is correct |
21 |
Correct |
74 ms |
190492 KB |
Output is correct |
22 |
Correct |
248 ms |
190496 KB |
Output is correct |
23 |
Correct |
143 ms |
190472 KB |
Output is correct |
24 |
Correct |
135 ms |
190412 KB |
Output is correct |
25 |
Correct |
132 ms |
190448 KB |
Output is correct |
26 |
Correct |
145 ms |
190432 KB |
Output is correct |
27 |
Correct |
114 ms |
190572 KB |
Output is correct |
28 |
Correct |
118 ms |
190484 KB |
Output is correct |
29 |
Correct |
160 ms |
190452 KB |
Output is correct |
30 |
Correct |
138 ms |
190500 KB |
Output is correct |