#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include <cassert>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric> //gcd(a,b)
#include<bitset>
#include <cstdlib>
#include <cstdint>
using namespace std;
#define ll long long
#define f first
//#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
#define int long long
#define double long double
const int mod=1e9+7,mxn=1e5+5,lg=60,inf=1e9,minf=-1e18,Mxn=1e6+50000;
int dp[103][103][1002][3];
int32_t main(){
fastio
//dp[i][num of com][cur sum][border have]
int n,l;cin>>n>>l;
vector<int>v(n);
for(int i=0;i<n;i++)cin>>v[i];
sort(all(v));
v.pb(v.back());
int nsum;
if(2*(v[1]-v[0]))dp[1][1][2*(v[1]-v[0])][0]=1;
if(v[1]-v[0]<=l)dp[1][1][v[1]-v[0]][1]=2;
for(int i=1;i<n;i++){
for(int j=1;j<=n;j++){
for(int sum=0;sum<=l;sum++){
for(int k=0;k<3;k++){
if(dp[i][j][sum][k]==0)continue;
//cout<<dp[i][j][sum][k]<<" "<<i<<" "<<j<<" "<<sum<<" "<<k<<" "<<"G\n";
//create
nsum=(sum+((v[i+1]-v[i])*((j+1)*2-k)));
if(nsum<=l&&nsum>=0){
dp[i+1][j+1][nsum][k]=(dp[i+1][j+1][nsum][k]+(dp[i][j][sum][k]*(j+1-k))%mod)%mod;
}
//merge
nsum=(sum+((v[i+1]-v[i])*((j-1)*2-k)));
if(nsum<=l&&nsum>=0)dp[i+1][j-1][nsum][k]=(dp[i+1][j-1][nsum][k]+(dp[i][j][sum][k]*(j-1))%mod)%mod;
//fill border
//fill border by creating new one
nsum=(sum+((v[i+1]-v[i])*(((j+1)*2)-k-1)));
if(nsum<=l&&nsum>=0&&k+1<3){
dp[i+1][j+1][nsum][k+1]=(dp[i+1][j+1][nsum][k+1]+(dp[i][j][sum][k]*(2-k))%mod)%mod;
}
/*
missing case where
a>b<c
*/
//fill border by attaching to the existing one
/*
nsum=(sum+(v[i+1]-v[i])*((j*2)-k-1));
if(nsum<=l&&nsum>=0&&k+1<3){
//cout<<"B\n";
dp[i+1][j][nsum][k+1]=(dp[i+1][j][nsum][k+1]+(dp[i][j][sum][k]*(2-k))%mod)%mod;
}*/
//attach
nsum=(sum+(v[i+1]-v[i])*((j*2)-k));
if(nsum<=l&&nsum>=0)dp[i+1][j][nsum][k]=(dp[i+1][j][nsum][k]+(dp[i][j][sum][k]*((j-k)*2+k))%mod)%mod;//stick it
}
}
}
}
int ans=0;
for(int i=0;i<=l;i++){
//cout<<dp[n][1][i][2]<<" "<<i<<'\n';
ans=(ans+dp[n][1][i][2])%mod;
}
cout<<ans;
/*
*/
return 0;
}
/*
*/
Compilation message
skyscraper.cpp: In function 'int32_t main()':
skyscraper.cpp:50:6: warning: '*' in boolean context, suggest '&&' instead [-Wint-in-bool-context]
50 | if(2*(v[1]-v[0]))dp[1][1][2*(v[1]-v[0])][0]=1;
| ~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2904 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |