#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
int n,l;
ll dp[2][1001][101][4];
int a[101];
int main(){
ios::sync_with_stdio(false);
cin >> n >> l;
if(n==1){
cout << "1\n";
return 0;
}
for(int i=1; i<=n ;i++) cin >> a[i];
sort(a+1,a+n+1);
dp[0][0][0][0]=1;
for(int i=1; i<=n ;i++){
int c=i&1;
int p=c^1;
for(int j=0; j<=l ;j++)
for(int k=0; k<=i ;k++)
for(int r=0; r<=2 ;r++)
dp[c][j][k][r]=0;
for(int j=0; j<=l ;j++)
for(int k=0; k<i ;k++)
for(int r=0; r<=2 ;r++){
int nj=j+(a[i]-a[i-1])*(2*k-r);
if(nj>l || dp[p][j][k][r]==0) continue;
//new set
dp[c][nj][k+1][r]=(dp[c][nj][k+1][r]+dp[p][j][k][r])%mod;
dp[c][nj][k+1][r+1]=(dp[c][nj][k+1][r+1]+dp[p][j][k][r]*(2-r))%mod;
//stick in ends
dp[c][nj][k][r]=(dp[c][nj][k][r]+dp[p][j][k][r]*(2*k-r))%mod;
dp[c][nj][k][r+1]=(dp[c][nj][k][r+1]+dp[p][j][k][r]*(k-r+(i==n && r==1 && k==1))*(2-r))%mod;
//join
int w=r*(k-r)+(k-r)*(k-r-1)+(i==n && r==2 && k==2);
dp[c][nj][k-1][r]=(dp[c][nj][k-1][r]+dp[p][j][k][r]*w)%mod;
}
}
ll ans=0;
for(int i=0; i<=l ;i++) ans=(ans+dp[n&1][i][1][2])%mod;
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
1016 KB |
Output is correct |
5 |
Correct |
7 ms |
6392 KB |
Output is correct |
6 |
Correct |
8 ms |
5752 KB |
Output is correct |
7 |
Correct |
3 ms |
1400 KB |
Output is correct |
8 |
Correct |
3 ms |
888 KB |
Output is correct |
9 |
Correct |
7 ms |
6008 KB |
Output is correct |
10 |
Correct |
3 ms |
1144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
760 KB |
Output is correct |
2 |
Correct |
2 ms |
888 KB |
Output is correct |
3 |
Correct |
2 ms |
632 KB |
Output is correct |
4 |
Correct |
2 ms |
888 KB |
Output is correct |
5 |
Correct |
2 ms |
888 KB |
Output is correct |
6 |
Correct |
2 ms |
892 KB |
Output is correct |
7 |
Correct |
2 ms |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
632 KB |
Output is correct |
9 |
Correct |
2 ms |
760 KB |
Output is correct |
10 |
Correct |
2 ms |
888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
1016 KB |
Output is correct |
5 |
Correct |
7 ms |
6392 KB |
Output is correct |
6 |
Correct |
8 ms |
5752 KB |
Output is correct |
7 |
Correct |
3 ms |
1400 KB |
Output is correct |
8 |
Correct |
3 ms |
888 KB |
Output is correct |
9 |
Correct |
7 ms |
6008 KB |
Output is correct |
10 |
Correct |
3 ms |
1144 KB |
Output is correct |
11 |
Correct |
2 ms |
760 KB |
Output is correct |
12 |
Correct |
2 ms |
888 KB |
Output is correct |
13 |
Correct |
2 ms |
632 KB |
Output is correct |
14 |
Correct |
2 ms |
888 KB |
Output is correct |
15 |
Correct |
2 ms |
888 KB |
Output is correct |
16 |
Correct |
2 ms |
892 KB |
Output is correct |
17 |
Correct |
2 ms |
504 KB |
Output is correct |
18 |
Correct |
2 ms |
632 KB |
Output is correct |
19 |
Correct |
2 ms |
760 KB |
Output is correct |
20 |
Correct |
2 ms |
888 KB |
Output is correct |
21 |
Correct |
2 ms |
632 KB |
Output is correct |
22 |
Correct |
50 ms |
5592 KB |
Output is correct |
23 |
Correct |
58 ms |
6520 KB |
Output is correct |
24 |
Correct |
49 ms |
5260 KB |
Output is correct |
25 |
Correct |
58 ms |
6648 KB |
Output is correct |
26 |
Correct |
50 ms |
5752 KB |
Output is correct |
27 |
Correct |
19 ms |
2064 KB |
Output is correct |
28 |
Correct |
23 ms |
2296 KB |
Output is correct |
29 |
Correct |
41 ms |
3960 KB |
Output is correct |
30 |
Correct |
58 ms |
6648 KB |
Output is correct |