【题目链接】
http://codeforces.com/contest/451/problem/E
【算法】
容斥原理
【代码】
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int P = 1e9 + ; int i,j,n,s,ans,MASK;
ll m,t;
ll a[],f[];
int inv[]; inline int power(int a,int n)
{
int res = ,b = a;
while (n)
{
if (n & ) res = 1ll * res * b % P;
b = 1ll * b * b % P;
n >>= ;
}
return res;
}
inline int C(ll x,int y)
{
int i,res = ;
if (y < || x < y || x < ) return ;
if (x == || y == ) return ;
x %= P;
for (i = x; i >= x - y + ; i--) res = 1ll * res * i % P;
for (i = ; i <= y; i++) res = 1ll * res * inv[i] % P;
return res;
} int main()
{ scanf("%d%I64d",&n,&m);
for (i = ; i <= n; i++) scanf("%I64d",&a[i]);
for (i = ; i <= ; i++) inv[i] = power(i,P-);
MASK = << n;
ans = ;
for (i = ; i < MASK; i++)
{
if (i == ) ans = (ans + C(n+m-,n-)) % P;
else
{
s = ;
t = n + m;
for (j = ; j < n; j++)
{
if (i & ( << j))
{
s++;
t -= a[j+];
}
}
t -= (s + );
if (s & ) ans = (ans - C(t,n-) + P) % P;
else ans = (ans + C(t,n-)) % P;
}
}
printf("%d\n",ans); return ; }