思路:多重集的组合,有公式
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 30;
ll a[maxn];
const int mod = 1e9+7;
int inv[20], n;
int power(int a, int b)
{
int c = 1;
for(;b;b>>=1)
{
if(b&1) c= (long long )c*a %mod;
a = (long long )a*a %mod;
}
return c;
}
int C(ll n, int r)
{
if(n<0|| r<0 ||n<r)return 0;
n%=mod;
if(n== 0 ||r== 0) return 1;
ll ans = 1;
for(int i =0;i<r;i++)
ans = ans *(n-i) %mod;
for(int i = 1;i<=r; i++)
ans = ans *inv[i]%mod;
return ans;
}
int main()
{
int n,m;
for(int i =1;i<=20;i++)
inv[i] = power(i, mod-2);
cin>>n>>m;
for(int i = 0;i<n;i++)cin>>a[i];
ll ans = 0;
for(int i = 0;i<(1<<n);i++)
{
ll cnt =0;
ll temp = n+m;
for(int j = 0;j<n;j++)
{
if(i&(1<<j))
{
cnt++;
temp -= a[j];
}
}
temp = temp - cnt-1;
if(cnt%2==0)
{
ans = (ans + C(temp, n-1))%mod;
}
else
{
ans = (ans - C(temp, n-1))%mod;
}
}
cout<< (ans +mod)%mod<<endl;
return 0;
}