#include <bits/stdc++.h>
#define Alora "cownav"
#define fi(i,a,b) for(int i = a; i <= b; i++)
#define fid(i,a,b) for(int i = a; i >= b; i--)
#define ll long long
#define f first
#define se second
#define pii pair<int, int>
#define getbit(i, j) ((i >> j) & 1)
#define all(v) v.begin(), v.end()
#define pb push_back
#define maxn 10053
const int M = 1e9 + 7;
using namespace std;
int n, l, r[55];
int res, C[55][maxn], gt[55], dp[2][55][maxn];
void add(int &x, int y){x = (x + y) % M;}
int mul(int x, int y) {return 1ll*x*y % M;}
void pre(){
fi(i, 1, l + n) C[0][i] = 1;
C[1][1] = 1;
fi(i, 2, l + n){
fi(j, 1, min(50, i)){
add(C[j][i], C[j][i - 1] + C[j - 1][i - 1]);
}
}
gt[0] = 1;
fi(i, 1, n) gt[i] = 1ll*gt[i - 1]*i % M;
}
void sub1(){
if(n == 1) {cout << l; exit(0);}
int len = l - (1 + r[1]*(n - 1));
if(len < 0){cout << 0; exit(0);}
len += n;
cout << C[n][len]*gt[n] % M;
exit(0);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
if(fopen(Alora".inp", "r")){
freopen(Alora".inp", "r", stdin);
freopen(Alora".out", "w", stdout);}
cin >> n >> l;
pre();
fi(i, 1, n) cin >> r[i];
sort(r + 1, r + n + 1);
if(r[1] == r[n]) sub1();
dp[0][0][0] = 1;
int t = 0;
fi(i, 1, n){
t ^= 1;
dp[t][0][0] = 0;
fi(j, 1, i){
fi(d, 1, l){
dp[t][j][d] = dp[1 - t][j - 1][d - 1]; // add new
if(d >= r[i]) add(dp[t][j][d], mul(dp[1 - t][j][d - r[i]], 2*j)); // add
if(d >= 2*r[i] - 1) add(dp[t][j][d], mul(dp[1 - t][j + 1][d - 2*r[i] + 1], (j + 1)*j)); // connect
}
}
}
fi(d, 1, l) add(res, mul(dp[t][1][d], C[l - d][l - d + n]));
cout << res;
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:45:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | freopen(Alora".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:46:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | freopen(Alora".out", "w", stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
10 ms |
13148 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
6 ms |
9048 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |