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
| #include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<cstdlib> #include<algorithm> #include<ctime> #include<iomanip> #include<queue> #include<stack> #include<map> #include<vector> #define gh() getchar() #define underMax(x,y) ((x)>(y)?(x):(y)) #define underMin(x,y) ((x)<(y)?(x):(y)) typedef long long ll; using namespace std; const int MAXN=21; const int Mod=1e9+7; template<class T> inline void underRead(T &x) { x=0; char ch=gh(),t=0; while(ch<'0'||ch>'9') t|=ch=='-',ch=gh(); while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=gh(); if(t) x=-x; } ll A[MAXN]; int down=1; inline int underQmi(int a,int k,int p) { int res=1; while(k) { if(k&1) res=(ll)res*a%p; a=(ll)a*a%p; k>>=1; } return res; } inline int underC(ll a,ll b) { if(a<b) return 0; int up=1; for(ll i=a;i>a-b;--i) up=i%Mod*up%Mod; return (ll)up*down%Mod; } int main() { ll n,m; underRead(n),underRead(m); for(int i=0;i<n;++i) underRead(A[i]); for(int j=1;j<n;++j) down=(ll)j*down%Mod; down=underQmi(down,Mod-2,Mod); int res=0; for(int i=0;i<1<<n;++i) { ll a=n+m-1,b=n-1; int sign=1; for(int j=0;j<n;++j) if(i>>j&1) { sign*=-1; a-=A[j]+1; } res=(res+underC(a,b)*sign)%Mod; } printf("%d",(res+Mod)%Mod); return 0; }
|