-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathE.cpp
81 lines (75 loc) · 1.59 KB
/
E.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* Author: RainAir
* Time: 2019-08-27 18:12:12
*/
#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define fi first
#define se second
#define U unsigned
#define P std::pair
#define Re register
#define LL long long
#define pb push_back
#define MP std::make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(Re int i = a;i <= b;++i)
#define ROF(i,a,b) for(Re int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
#define int LL
const int MAXN = 20+5;
const int ha = 1e9 + 7;
inline int qpow(int a,int n=ha-2){
int res = 1;
while(n){
if(n & 1) res = 1ll*res*a%ha;
a = 1ll*a*a%ha;
n >>= 1;
}
return res;
}
inline int C(int n,int m){
if(n < 0) return 1;
if(n < m) return 0;
if(!m) return 1;
int res = 1;
FOR(i,n-m+1,n) res = 1ll*res*(i%ha)%ha;
int t = 1;
FOR(i,1,m) t = 1ll*t*i%ha;
return 1ll*res*qpow(t)%ha;
}
int n,s;
int a[MAXN];
inline int pc(int x){
int res = 0;
while(x) res += x&1,x >>= 1;
return res;
}
signed main(){
scanf("%lld%lld",&n,&s);
FOR(i,1,n) scanf("%lld",a+i);
LL ans = 0;
FOR(S,0,(1<<n)-1){
int t = s;
FOR(i,0,n-1){
if((1<<i)&S) t -= a[i+1]+1;
}
if(t < 0) continue;
ans = (ans+(pc(S)&1 ? -1 : 1)*C(t+n-1,n-1)%ha+ha)%ha;
}
printf("%lld\n",ans);
return 0;
}