Devu wants to decorate his garden with flowers. He has purchased n boxes, where the i-th box contains fi flowers. All flowers in a single box are of the same color (hence they are indistinguishable). Also, no two boxes have flowers of the same color.

Now Devu wants to select exactly s flowers from the boxes to decorate his garden. Devu would like to know, in how many different ways can he select the flowers from each box? Since this number may be very large, he asks you to find the number modulo (109 + 7).

Devu considers two ways different if there is at least one box from which different number of flowers are selected in these two ways.

Input

The first line of input contains two space-separated integers n and s (1 ≤ n ≤ 20, 0 ≤ s ≤ 1014).

The second line contains n space-separated integers f1, f2, ... fn (0 ≤ fi ≤ 1012).

Output

Output a single integer — the number of ways in which Devu can select the flowers modulo (109 + 7).

Example

Input
2 3
1 3
Output
2
Input
2 4
2 2
Output
1
Input
3 5
1 3 2
Output
3

Note

Sample 1. There are two ways of selecting 3 flowers: {1, 2} and {0, 3}.

Sample 2. There is only one way of selecting 4 flowers: {2, 2}.

Sample 3. There are three ways of selecting 5 flowers: {1, 2, 2}, {0, 3, 2}, and {1, 3, 1}.

#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
#define mod 1000000007
using namespace std;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
ll qpow(ll a,ll b)
{
ll ans=;
while(b)
{
if(b&)ans=(ans*a)%mod;
a=(a*a)%mod;
b>>=;
}
return ans;
}
ll getc(ll a,ll b)
{
if(a<b)return ;
if(b>a-b)b=a-b;
ll s1=,s2=;
for(ll i=;i<b;i++)
{
s1=s1*(a-i)%mod;
s2=s2*(i+)%mod;
}
return s1*qpow(s2,mod-)%mod;
}
ll lucas(ll n,ll k)
{
if(k==)return ;
return getc(n%mod,k%mod)*lucas(n/mod,k/mod)%mod;
}
int n;
ll s,f[];
ll solve()
{
ll ans=;
for(int i=;i<(<<n);i++)
{
ll sign=,sum=s;
for(int j=;j<n;j++)
{
if(i&(<<j))
{
sum-=f[j]+;
sign*=-;
}
}
if(sum<)continue;
ans+=sign*lucas(sum+n-,n-);
ans%=mod;
}
return (ans+mod)%mod;
}
int main()
{
cin>>n>>s;
for(int i=;i<n;i++)
cin>>f[i];
printf("%lld\n",solve());
return ;
}

Devu and Flowers lucas定理+容斥原理的更多相关文章

  1. 2018.10.31 bzoj4737: 组合数问题(lucas定理+容斥原理+数位dp)

    传送门 这是一道让我重新认识lucaslucaslucas的题. 考虑到lucaslucaslucas定理: (nm)≡(n%pm%p)∗(npmp)\binom n m \equiv \binom ...

  2. CF451E Devu and Flowers (隔板法 容斥原理 Lucas定理 求逆元)

    Codeforces Round #258 (Div. 2) Devu and Flowers E. Devu and Flowers time limit per test 4 seconds me ...

  3. codeforces 451E. Devu and Flowers 容斥原理+lucas

    题目链接 给n个盒子, 每个盒子里面有f[i]个小球, 然后一共可以取sum个小球.问有多少种取法, 同一个盒子里的小球相同, 不同盒子的不同. 首先我们知道, n个盒子放sum个小球的方式一共有C( ...

  4. Codeforces 451E Devu and Flowers(容斥原理)

    题目链接:Codeforces 451E Devu and Flowers 题目大意:有n个花坛.要选s支花,每一个花坛有f[i]支花.同一个花坛的花颜色同样,不同花坛的花颜色不同,问说能够有多少种组 ...

  5. Codeforces Round #258 E Devu and Flowers --容斥原理

    这题又是容斥原理,最近各种做容斥原理啊.当然,好像题解给的不是容斥原理的方法,而是用到Lucas定理好像.这里只讲容斥的做法. 题意:从n个容器中总共取s朵花出来,问有多少种情况.其中告诉你每个盒子中 ...

  6. BZOJ3129/洛谷P3301方程(SDOI2013)容斥原理+扩展Lucas定理

    题意:给定方程x1+x2+....xn=m,每个x是正整数.但是对前n1个数做了限制x1<=a1,x2<=a2...xn1<=an1,同时对第n1+1到n1+n2个数也做了限制xn1 ...

  7. 【bzoj3782】上学路线 dp+容斥原理+Lucas定理+中国剩余定理

    题目描述 小C所在的城市的道路构成了一个方形网格,它的西南角为(0,0),东北角为(N,M).小C家住在西南角,学校在东北角.现在有T个路口进行施工,小C不能通过这些路口.小C喜欢走最短的路径到达目的 ...

  8. Codeforces 451 E. Devu and Flowers(组合数学,数论,容斥原理)

    传送门 解题思路: 假如只有 s 束花束并且不考虑 f ,那么根据隔板法的可重复的情况时,这里的答案就是 假如说只有一个 f 受到限制,其不合法时一定是取了超过 f 的花束 那么根据组合数,我们仍然可 ...

  9. Lucas定理及其应用

    Lucas定理这里有详细的证明. 其实就是针对n, m很大时,要求组合数C(n, m) % p, 一般来说如果p <= 10^5,那么就能很方便的将n,m转化为10^5以下这样就可以按照乘法逆元 ...

随机推荐

  1. [BZOJ1025][SCOI2009]游戏 DP+置换群

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1025 题目中的排数就是多少次回到原来的序列.很显然对于题目所描述的任意一种对应法则,其中一 ...

  2. 用vue写的移动端车牌号输入法

    效果图: (录制了视频演示,然而不会上传.....心塞.....) 本页面所在项目已上传GitHub,github下载地址:https://github.com/dan-Zd/car-vueapp  ...

  3. GridView 中绑定DropDownList ,下拉框默认选中Label的值

    在GridView中,我们 有时候要绑定值. 前台绑定的代码可以这样 <asp:TemplateField HeaderText="当前状态" ItemStyle-Horiz ...

  4. 短视频SDK用于旅游行业

    超级简单易用的短视频SDK来自RDSDK.COM.锐动天地为开发者提供短视频编辑.视频直播.特效.录屏.编解码.视频转换,等多种解决方案,涵盖PC.iOS.Android多平台.以市场为导向,不断打磨 ...

  5. [转]c++应用程序文件的编译过程

    原文地址 这里讲下C++文件的编译过程及其中模板的编译过程: 一:一般的C++应用程序的编译过程.    一般说来,C++应用程序的编译过程分为三个阶段.模板也是一样的. 在cpp文件中展开inclu ...

  6. JS Object 属性判断

    in 方法 var shapeInfo = {name:“lium”}; if (“name” in shapeInfo) {...}

  7. mybatis generator 覆盖xml文件

    mybatis generator默认采用追加方式生成,所以我们如果要重新生成代码的时候那么要先删除原来的文件. 解决办法: 1:创建一个自定义补丁类. OverwriteXmlPlugin.java ...

  8. Stack in c#

    public static void SaveStack() { string result = "Hello World"; Stack st = new Stack(); fo ...

  9. JAVA基础——数据流

    DataInputStream 类和DataOutputStream 类 在前面的学习中,我们知道数据流处理的数据都是指字节或字节数组,但实际上很多时候不是这样的,它需要数据流能直接读.写各种各样的j ...

  10. git命令初级

    git是开源的分布式版本控制系统,分布式主要区别于集中式代表CVS(Concurrent Version System,遵从C/S架构,同步比较笨拙.)和SVN(Subversion),linux开发 ...