#include <bits/stdc++.h>
using namespace std;
#define foru(i, a, b) for(int i = (a); i <= (b); ++i)
#define ford(i, a, b) for(int i = (a); i >= (b); --i)
#define rep(i, a) for(int i = 0; i < (a); ++i)
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define bit(s, i) (((s) >> (i)) & 1)
#define ii pair <int, int>
#define fi first
#define se second
#define ll long long
#define eb emplace_back
#define pb push_back
#define __builtin_popcount __builtin_popcountll
template <class X, class Y>
bool maxi(X &x, Y y) {
if(x < y) {
x = y;
return true;
}
return false;
}
template <class X, class Y>
bool mini(X &x, Y y) {
if(x > y) {
x = y;
return true;
}
return false;
}
const int N=55;
const int L=10101;
const int mod=1e9+7;
int n,l,r[N],dp[N][N][L][3];
int f[L],invf[L];
inline void add(int &a, int b){
a+=b; if(a>=mod) a-=mod;
}
inline int mul(int a, int b){
return (ll)a*b % mod;
}
inline int pw(int a, int b){
int res=1;
while(b>0){
if(b&1) res=mul(res,a);
a=mul(a,a);
b>>=1;
}
return res;
}
inline int nCk(int n, int k){
return mul(f[n], mul(invf[k], invf[n-k]));
}
void solve(){
cin>>n>>l;
foru(i,1,n) cin>>r[i];
if(n==1){
cout<<l<<'\n';
return;
}
sort(r+1, r+1+n, greater<int>());
dp[0][0][0][0]=1;
foru(i,0,n-1) foru(cc,0,i) foru(len,0,l) foru(fe,0,2) if(dp[i][cc][len][fe]>0){
int dpt=dp[i][cc][len][fe];
if(len+1+(r[i+1]-1)*2<=l)
add(dp[i+1][cc+1][len+1+(r[i+1]-1)*2][fe], mul(dpt,cc+1-fe));
if(fe<2 && len+r[i+1]<=l)
add(dp[i+1][cc+1][len+r[i+1]][fe+1], mul(dpt,2-fe));
if(len+r[i+1]<=l)
add(dp[i+1][cc][len+r[i+1]][fe], mul(dpt,2*cc-fe));
if(fe<2 && len+1<=l)
add(dp[i+1][cc][len+1][fe+1], mul(dpt,2-fe));
if(cc>1 && len+1<=l)
add(dp[i+1][cc-1][len+1][fe], mul(dpt,cc-1));
}
f[0]=1;
foru(i,1,L-1) f[i]=mul(f[i-1],i);
invf[L-1]=pw(f[L-1], mod-2);
ford(i,L-2,0) invf[i]=mul(invf[i+1],i+1);
int res=0;
foru(i,n,l){
add(res, mul(dp[n][1][i][2], nCk(n+l-i,n)));
}
cout<<res<<'\n';
}
int32_t main() {
#define task "test"
if(fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
cin.tie(0)->sync_with_stdio(0);
int tc = 1; // cin >> tc;
foru(i, 1, tc){
solve();
}
}
Compilation message (stderr)
Main.cpp: In function 'int32_t main()':
Main.cpp:105:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
105 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:106:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
106 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |