#include<iostream>
#include<algorithm>
using namespace std;
typedef long long int lld;
#define MOD 1000000007
lld DP[101][2][2][101][1001];
int n,l;
int arr[1001];
lld ans(int i, int L,int R , int CC, int pen){
if(i>0)pen+=(arr[i]-arr[i-1])*(2*CC+L+R);
//cout<<pen<<endl;
if(CC<0 || pen>l)return 0;
if(i==n-1){
if(CC==0){
return 1;
}return 0;
}
if(DP[i][L][R][CC][pen]!=-1)return DP[i][L][R][CC][pen];
DP[i][L][R][CC][pen]=0;
DP[i][L][R][CC][pen]+=CC*(CC-1)*ans(i+1,L,R,CC-1,pen);
DP[i][L][R][CC][pen]%=MOD;
DP[i][L][R][CC][pen]+=2*CC*ans(i+1,L,R,CC,pen);
DP[i][L][R][CC][pen]%=MOD;
DP[i][L][R][CC][pen]+=ans(i+1,L,R,CC+1,pen);
DP[i][L][R][CC][pen]%=MOD;
DP[i][L][R][CC][pen]+=ans(i+1,1,R,CC,pen);
DP[i][L][R][CC][pen]%=MOD;
DP[i][L][R][CC][pen]+=ans(i+1,L,1,CC,pen);
DP[i][L][R][CC][pen]%=MOD;
DP[i][L][R][CC][pen]+=CC*ans(i+1,1,R,CC-1,pen);
DP[i][L][R][CC][pen]%=MOD;
DP[i][L][R][CC][pen]+=CC*ans(i+1,L,1,CC-1,pen);
DP[i][L][R][CC][pen]%=MOD;
return DP[i][L][R][CC][pen];
}
int main(){
cin>>n>>l;
for(int i=0;i<n;i++)cin>>arr[i];
sort(arr,arr+n);
for(int i=0;i<=n;i++){
for(int j=0;j<=n;j++){
for(int k=0;k<=l;k++){
DP[i][0][0][j][k]=-1;
DP[i][1][0][j][k]=-1;
DP[i][0][1][j][k]=-1;
DP[i][1][1][j][k]=-1;
}
}
}
cout<<ans(0,0,0,0,0)<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
632 KB |
Output is correct |
4 |
Correct |
3 ms |
1272 KB |
Output is correct |
5 |
Correct |
4 ms |
3064 KB |
Output is correct |
6 |
Correct |
4 ms |
2936 KB |
Output is correct |
7 |
Correct |
3 ms |
2168 KB |
Output is correct |
8 |
Correct |
3 ms |
1912 KB |
Output is correct |
9 |
Correct |
4 ms |
3064 KB |
Output is correct |
10 |
Correct |
3 ms |
2040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3448 KB |
Output is correct |
2 |
Correct |
5 ms |
4728 KB |
Output is correct |
3 |
Correct |
5 ms |
4344 KB |
Output is correct |
4 |
Correct |
6 ms |
4728 KB |
Output is correct |
5 |
Correct |
5 ms |
4728 KB |
Output is correct |
6 |
Correct |
5 ms |
4728 KB |
Output is correct |
7 |
Correct |
5 ms |
4216 KB |
Output is correct |
8 |
Correct |
5 ms |
4344 KB |
Output is correct |
9 |
Correct |
5 ms |
4472 KB |
Output is correct |
10 |
Correct |
5 ms |
4600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
632 KB |
Output is correct |
4 |
Correct |
3 ms |
1272 KB |
Output is correct |
5 |
Correct |
4 ms |
3064 KB |
Output is correct |
6 |
Correct |
4 ms |
2936 KB |
Output is correct |
7 |
Correct |
3 ms |
2168 KB |
Output is correct |
8 |
Correct |
3 ms |
1912 KB |
Output is correct |
9 |
Correct |
4 ms |
3064 KB |
Output is correct |
10 |
Correct |
3 ms |
2040 KB |
Output is correct |
11 |
Correct |
4 ms |
3448 KB |
Output is correct |
12 |
Correct |
5 ms |
4728 KB |
Output is correct |
13 |
Correct |
5 ms |
4344 KB |
Output is correct |
14 |
Correct |
6 ms |
4728 KB |
Output is correct |
15 |
Correct |
5 ms |
4728 KB |
Output is correct |
16 |
Correct |
5 ms |
4728 KB |
Output is correct |
17 |
Correct |
5 ms |
4216 KB |
Output is correct |
18 |
Correct |
5 ms |
4344 KB |
Output is correct |
19 |
Correct |
5 ms |
4472 KB |
Output is correct |
20 |
Correct |
5 ms |
4600 KB |
Output is correct |
21 |
Correct |
25 ms |
29472 KB |
Output is correct |
22 |
Correct |
563 ms |
196888 KB |
Output is correct |
23 |
Correct |
513 ms |
320176 KB |
Output is correct |
24 |
Correct |
393 ms |
320180 KB |
Output is correct |
25 |
Correct |
423 ms |
320100 KB |
Output is correct |
26 |
Correct |
393 ms |
320120 KB |
Output is correct |
27 |
Correct |
253 ms |
241912 KB |
Output is correct |
28 |
Correct |
274 ms |
259844 KB |
Output is correct |
29 |
Correct |
395 ms |
320156 KB |
Output is correct |
30 |
Correct |
425 ms |
319992 KB |
Output is correct |