This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=105;
const int M=1005;
const int mod=1e9+7;
int n,l;
int a[N];
ll dp[N][N][M][4];
ll 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)%mod;
dp[i][j-1][res][e]%=mod;
dp[i][j][res][e]+=dp[i-1][j][k][e]*(2*j-e)%mod;
dp[i][j][res][e]%=mod;
dp[i][j+1][res][e]+=dp[i-1][j][k][e]*(j+1-e)%mod;
dp[i][j+1][res][e]%=mod;
dp[i][j][res][e+1]+=dp[i-1][j][k][e]*(2-e)%mod;
dp[i][j][res][e+1]%=mod;
dp[i][j+1][res][e+1]+=dp[i-1][j][k][e]*(2-e)%mod;
dp[i][j+1][res][e+1]%=mod;
}
}
}
}
for(int i=0;i<=l;i++){
ans+=dp[n][1][i][2];
ans%=mod;
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |