#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=105;
const int M=1005;
const int mod=1e9+7;
struct mint{
int x;
mint(ll x=0ll):x(calc(x%mod)){}
int calc(int x){
if(x>=mod)x-=mod;
if(x<0)x+=mod;
return x;
}
mint& operator+=(const mint &rhs){return x=calc(x+rhs.x),*this;}
mint& operator-=(const mint &rhs){return x=calc(x-rhs.x),*this;}
mint& operator*=(const mint &rhs){return x=(1ll*x*rhs.x)%mod,*this;}
friend mint operator+(const mint &lhs,const mint &rhs){return mint(lhs)+=rhs;};
friend mint operator-(const mint &lhs,const mint &rhs){return mint(lhs)-=rhs;};
friend mint operator*(const mint &lhs,const mint &rhs){return mint(lhs)*=rhs;};
};
int n,l;
int a[N];
mint dp[N][N][M][4];
mint ans;
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> l;
for(int i=1;i<=n;i++)cin >> a[i];
if(n==1)cout << 1,exit(0);
sort(a+1,a+n+1);
dp[1][1][0][0]=1;
dp[1][1][0][1]=2;
for(int i=2;i<=n;i++){
for(int j=1;j<i;j++){
for(int k=0;k<=l;k++){
for(int e=0;e<3;e++){
int res=k+(a[i]-a[i-1])*(2*j-e);
if(res>l)continue;
dp[i][j-1][res][e]+=dp[i-1][j][k][e]*(j-1);
dp[i][j][res][e]+=dp[i-1][j][k][e]*(2*j-e);
dp[i][j+1][res][e]+=dp[i-1][j][k][e]*(j+1-e);
dp[i][j][res][e+1]+=dp[i-1][j][k][e]*(2-e);
dp[i][j+1][res][e+1]+=dp[i-1][j][k][e]*(2-e);
}
}
}
}
for(int i=0;i<=l;i++)ans+=dp[n][1][i][2];
cout << ans.x;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
173724 KB |
Output is correct |
2 |
Correct |
65 ms |
173728 KB |
Output is correct |
3 |
Correct |
66 ms |
173716 KB |
Output is correct |
4 |
Correct |
64 ms |
173756 KB |
Output is correct |
5 |
Correct |
65 ms |
173644 KB |
Output is correct |
6 |
Correct |
69 ms |
173636 KB |
Output is correct |
7 |
Correct |
73 ms |
173708 KB |
Output is correct |
8 |
Correct |
67 ms |
173692 KB |
Output is correct |
9 |
Correct |
69 ms |
173672 KB |
Output is correct |
10 |
Correct |
66 ms |
173716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
173656 KB |
Output is correct |
2 |
Correct |
67 ms |
173676 KB |
Output is correct |
3 |
Correct |
69 ms |
173676 KB |
Output is correct |
4 |
Correct |
70 ms |
173764 KB |
Output is correct |
5 |
Correct |
77 ms |
173764 KB |
Output is correct |
6 |
Correct |
66 ms |
173708 KB |
Output is correct |
7 |
Correct |
67 ms |
173660 KB |
Output is correct |
8 |
Correct |
67 ms |
173716 KB |
Output is correct |
9 |
Correct |
68 ms |
173716 KB |
Output is correct |
10 |
Correct |
68 ms |
173724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
173724 KB |
Output is correct |
2 |
Correct |
65 ms |
173728 KB |
Output is correct |
3 |
Correct |
66 ms |
173716 KB |
Output is correct |
4 |
Correct |
64 ms |
173756 KB |
Output is correct |
5 |
Correct |
65 ms |
173644 KB |
Output is correct |
6 |
Correct |
69 ms |
173636 KB |
Output is correct |
7 |
Correct |
73 ms |
173708 KB |
Output is correct |
8 |
Correct |
67 ms |
173692 KB |
Output is correct |
9 |
Correct |
69 ms |
173672 KB |
Output is correct |
10 |
Correct |
66 ms |
173716 KB |
Output is correct |
11 |
Correct |
77 ms |
173656 KB |
Output is correct |
12 |
Correct |
67 ms |
173676 KB |
Output is correct |
13 |
Correct |
69 ms |
173676 KB |
Output is correct |
14 |
Correct |
70 ms |
173764 KB |
Output is correct |
15 |
Correct |
77 ms |
173764 KB |
Output is correct |
16 |
Correct |
66 ms |
173708 KB |
Output is correct |
17 |
Correct |
67 ms |
173660 KB |
Output is correct |
18 |
Correct |
67 ms |
173716 KB |
Output is correct |
19 |
Correct |
68 ms |
173716 KB |
Output is correct |
20 |
Correct |
68 ms |
173724 KB |
Output is correct |
21 |
Correct |
67 ms |
173724 KB |
Output is correct |
22 |
Correct |
179 ms |
173660 KB |
Output is correct |
23 |
Correct |
180 ms |
173700 KB |
Output is correct |
24 |
Correct |
183 ms |
173760 KB |
Output is correct |
25 |
Correct |
181 ms |
173764 KB |
Output is correct |
26 |
Correct |
164 ms |
173720 KB |
Output is correct |
27 |
Correct |
107 ms |
173708 KB |
Output is correct |
28 |
Correct |
120 ms |
173760 KB |
Output is correct |
29 |
Correct |
168 ms |
173768 KB |
Output is correct |
30 |
Correct |
180 ms |
173672 KB |
Output is correct |