和《组合数学》里面将生成函数那里的几个例题差不多。根据给出的数据,列出来 (1+x)∗(1+x+x2+x3)∗(1+x+x2) ,展开后就能得到结果。不过看了看Si的范围就懵逼了。乖乖的找题解:http://www.cnblogs.com/L-Ecry/p/3898771.html
思路: 这就相当于把k朵花放到n个瓶子里,有多少方法,如果没限制的话,隔板法就好了。可是这里有限制,就要容斥了,如果一个瓶子里放的花的数量超出瓶子放花数量的上线,就减掉,如果两个瓶子同时超出上线的话,就加上。。。然后++–。。。
tle了好几发,发现我的lucas定理的板子有问题。。。
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL p = 1e9+7;
LL n,m;
LL quick_mod(LL a, LL b)
{
LL ans = 1;
a %= p;
while(b)
{
if(b & 1)
{
ans = ans * a % p;
b--;
}
b >>= 1;
a = a * a % p;
}
return ans;
}
LL C(LL n, LL m)
{
if(m > n) return 0;
LL a = 1,b = 1;
for(int i=1; i<=m; i++)
{
a = a * (n + i - m) % p;
b = b * i % p;
}
return a*quick_mod(b,p-2)%p;
}
LL Lucas(LL n, LL m)
{
if(m == 0) return 1;
return C(n % p, m % p) * Lucas(n / p, m / p) % p;
}
LL f[30],K;
void solve()
{
int limit = (1<<n);
int cnt;
LL res = 0;
LL sum;
for(int i = 0; i < limit; ++i)
{
sum = K;
cnt = 0;
for(int j = 0; j < n; ++j)
{
if(i&(1<<j))
{
++cnt;
sum -= (f[j]+1);
}
}
if(sum < 0) continue;
if(!(cnt&1))
res = (res + Lucas(sum+n-1,n-1))%p;
else
res = ((res - Lucas(sum+n-1,n-1))%p+p)%p;
}
cout << res <<endl;
}
int main()
{
ios::sync_with_stdio(false);
cin >> n >> K;
for(int i = 0; i < n; ++i)
cin >> f[i];
solve();
return 0;
}