首先我们知道,把m个小球放进n个桶里,桶可以为空的问题,答案是cal (m+n-1,n-1)
在实际中有x1<=A1,x2<=A2,x3<=A3……xn<=An等条件,此时就需要同时满足这N个条件,也就是有的桶里面的球超出了他的容量,所以就考虑容斥。
也就是至少不满足其中一个条件的方案。就可以用总方案减去这些方案就可以得出答案。
二进制枚举,如果枚举到当前x,那么这个不合法的方案数有
cal (m+n-1-(a[x]+1),n-1)种。。。。。
然后就能算出答案了
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#include<map>
#include<bitset>
#include<unordered_map>
using namespace std;
#define LL long long
typedef unsigned long long ull;
#define eps (1e-9)
const int maxn = 45;
const int inf = 0x3f3f3f3f;
const int bas = 131;
const LL mod = 1e9 + 7;
LL a[maxn], inv;
LL qpow(LL a, LL b)
{
LL res = 1;
while (b)
{
if (b & 1)res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
LL cal(LL a, LL b)
{
if (a < b)return 0;
else if (a == b)return 1;
LL res = 1;
for (LL i = a; i > (a - b); i--)
{
res = i % mod * res % mod;
}
return res * inv % mod;
}
int main()
{
LL n, m;
scanf("%lld%lld", &n, &m);
for (int i = 0; i < n; i++)
{
scanf("%lld", &a[i]);
}
inv = 1;
for (LL i = 2; i < n; i++)
{
inv = inv * i % mod;
}
inv = qpow(inv, mod - 2);
LL ans = 0;
for (int i = 0; i < (1 << n); i++)
{
LL n1 = m + n - 1, m1 = n - 1, f1 = 0;
for (int j = 0; j < n; j++)
{
if ((i >> j) & 1)
{
f1++;
n1 -= (a[j] + 1);
}
}
LL tmp = cal(n1, m1);
if (f1 & 1)ans = ((ans - tmp) % mod + mod) % mod;
else ans = (ans + tmp) % mod;
}
printf("%lld", ans);
return 0;
}