#include <bits/stdc++.h>
using namespace std ;
const int mod = 1e9 + 7 ;
int Add(int x , int y)
{
int z = x + y ;
if(z >= mod)
z -= mod ;
return z ;
}
int Sub(int x , int y)
{
int z = x - y ;
if(z < 0)
z += mod ;
return z ;
}
int Mul(int x , int y)
{
return (x * 1ll * y) % mod ;
}
int powlog(int base , int power)
{
if(power == 0)
return 1 ;
int x = powlog(base , power / 2) ;
x = Mul(x , x) ;
if(power & 1)
x = Mul(x , base) ;
return x ;
}
int modinv(int x)
{
return powlog(x , mod-2) ;
}
int Div(int x , int y)
{
return Mul(x , modinv(y)) ;
}
struct combination
{
vector<int>fact , inv ;
combination(int sz) : fact(sz + 1) , inv(sz + 1)
{
fact[0] = 1 ;
inv[0] = 1 ;
for(int i = 1 ; i <= sz ; ++i)
fact[i] = Mul(fact[i-1] , i) ;
inv[sz] = modinv(fact[sz]) ;
for(int i = sz-1 ; i >= 1 ; --i)
inv[i] = Mul(inv[i+1] , i+1) ;
}
int choose(int n , int k) const
{
if(k < 0 || n < k)
return 0 ;
return Mul(Mul(fact[n] , inv[k]) , inv[n - k]) ;
}
};
const int MAX = 2e4 + 10 ;
const int MAXN = 50 + 10 ;
combination comb(MAX) ;
int arr[MAXN] ;
int n , m ;
int dp[MAXN][MAXN][MAX] ;
int stars_and_bars(int n , int k)
{
return comb.choose(n+k-1 , k-1) ;
}
int main()
{
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
cin>>n>>m ;
for(int i = 1 ; i <= n ; ++i)
cin>>arr[i] ;
sort(arr+1 , arr+n+1) ;
dp[0][0][0] = 1 ;
for(int i = 1 ; i <= n ; ++i)
{
for(int j = 1 ; j <= i ; ++j)
{
for(int k = 0 ; k <= m ; ++k)
{
dp[i][j][k] = Mul(dp[i-1][j-1][k] , j) ;
if(k >= arr[i]-1)
dp[i][j][k] = Add(dp[i][j][k] , Mul(2 , Mul(dp[i-1][j][k-(arr[i]-1)] , j))) ;
if(k >= 2*(arr[i]-1))
dp[i][j][k] = Add(dp[i][j][k] , Mul(dp[i-1][j+1][k-2*(arr[i]-1)] , j)) ;
}
}
}
int ans = 0 ;
for(int k = 0 ; k+n <= m ; ++k)
ans = Add(ans , Mul(dp[n][1][k] , stars_and_bars(m-k-n , n+1))) ;
return cout<<ans<<"\n" , 0 ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
154 ms |
55788 KB |
Output is correct |
2 |
Correct |
4 ms |
6100 KB |
Output is correct |
3 |
Correct |
8 ms |
2900 KB |
Output is correct |
4 |
Correct |
3 ms |
852 KB |
Output is correct |
5 |
Correct |
10 ms |
4192 KB |
Output is correct |
6 |
Correct |
45 ms |
16684 KB |
Output is correct |
7 |
Correct |
40 ms |
30204 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
14 ms |
15068 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2900 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
8 ms |
2876 KB |
Output is correct |
4 |
Correct |
2 ms |
724 KB |
Output is correct |
5 |
Correct |
7 ms |
2792 KB |
Output is correct |
6 |
Correct |
2 ms |
852 KB |
Output is correct |
7 |
Correct |
8 ms |
2900 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
852 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3056 KB |
Output is correct |
2 |
Correct |
2 ms |
1492 KB |
Output is correct |
3 |
Correct |
3 ms |
3052 KB |
Output is correct |
4 |
Correct |
2 ms |
1748 KB |
Output is correct |
5 |
Correct |
3 ms |
3028 KB |
Output is correct |
6 |
Correct |
1 ms |
1364 KB |
Output is correct |
7 |
Correct |
4 ms |
3048 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
2 ms |
1640 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
154 ms |
55788 KB |
Output is correct |
2 |
Correct |
4 ms |
6100 KB |
Output is correct |
3 |
Correct |
8 ms |
2900 KB |
Output is correct |
4 |
Correct |
3 ms |
852 KB |
Output is correct |
5 |
Correct |
10 ms |
4192 KB |
Output is correct |
6 |
Correct |
45 ms |
16684 KB |
Output is correct |
7 |
Correct |
40 ms |
30204 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
14 ms |
15068 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
8 ms |
2900 KB |
Output is correct |
12 |
Correct |
2 ms |
596 KB |
Output is correct |
13 |
Correct |
8 ms |
2876 KB |
Output is correct |
14 |
Correct |
2 ms |
724 KB |
Output is correct |
15 |
Correct |
7 ms |
2792 KB |
Output is correct |
16 |
Correct |
2 ms |
852 KB |
Output is correct |
17 |
Correct |
8 ms |
2900 KB |
Output is correct |
18 |
Correct |
1 ms |
852 KB |
Output is correct |
19 |
Correct |
1 ms |
852 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
3 ms |
3056 KB |
Output is correct |
22 |
Correct |
2 ms |
1492 KB |
Output is correct |
23 |
Correct |
3 ms |
3052 KB |
Output is correct |
24 |
Correct |
2 ms |
1748 KB |
Output is correct |
25 |
Correct |
3 ms |
3028 KB |
Output is correct |
26 |
Correct |
1 ms |
1364 KB |
Output is correct |
27 |
Correct |
4 ms |
3048 KB |
Output is correct |
28 |
Correct |
1 ms |
724 KB |
Output is correct |
29 |
Correct |
2 ms |
1640 KB |
Output is correct |
30 |
Correct |
1 ms |
724 KB |
Output is correct |
31 |
Correct |
151 ms |
55764 KB |
Output is correct |
32 |
Correct |
92 ms |
35404 KB |
Output is correct |
33 |
Correct |
171 ms |
55796 KB |
Output is correct |
34 |
Correct |
31 ms |
12172 KB |
Output is correct |
35 |
Correct |
154 ms |
55720 KB |
Output is correct |
36 |
Correct |
9 ms |
3784 KB |
Output is correct |
37 |
Correct |
151 ms |
55708 KB |
Output is correct |
38 |
Correct |
30 ms |
13328 KB |
Output is correct |
39 |
Correct |
150 ms |
55732 KB |
Output is correct |
40 |
Correct |
55 ms |
16896 KB |
Output is correct |
41 |
Correct |
152 ms |
55892 KB |
Output is correct |
42 |
Correct |
1 ms |
872 KB |
Output is correct |
43 |
Correct |
143 ms |
55768 KB |
Output is correct |
44 |
Correct |
15 ms |
6244 KB |
Output is correct |
45 |
Correct |
145 ms |
55804 KB |
Output is correct |
46 |
Correct |
1 ms |
548 KB |
Output is correct |
47 |
Correct |
26 ms |
17272 KB |
Output is correct |
48 |
Correct |
12 ms |
10212 KB |
Output is correct |
49 |
Correct |
3 ms |
1492 KB |
Output is correct |
50 |
Correct |
1 ms |
852 KB |
Output is correct |