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. php防止页面刷新代码

    //代理IP直接退出 empty($_SERVER['HTTP_VIA']) or exit('Access Denied'); //防止快速刷新 session_start(); $seconds ...

  2. (2) Tomcat启动Jenkins

    Tomcat启动Jenkins 1. 下载Tomact,解压缩到指定目录. 2. 下载Jenkins.war文件,方到Tomact的WebApps下面即可. 3. 修改Tomcat的HTTP端口和默认 ...

  3. sql语句中截取字符串

    今天在开发过程中因为要用到合并单元格,在程序里实现了以后,查出来的数据太长,都把格式撑大了,后来想想可以在sql语句查询的时候就截取,就去网上找了一下,挺好用,就转了过来: 合并单元格: /// &l ...

  4. EasyUI edatagrid插件使用小计

    html片段 <table id="menuview" style="width:100%"> <thead> <tr> & ...

  5. 数据库系统概论(1)——Chap. 1 Introduction

    数据库系统概论--Introduction 一.数据库的4个基本概念 数据(data):数据是数据库中存储的基本单位.我们把描述事物的符号记录称为数据.数据和关于数据的解释是不可分的,数据的含义称为数 ...

  6. Python界面编程之六----布局

    布局(转载于–学点编程吧)通过实践可知采用了布局之后能够让我们的程序在使用上更加美观,不会随着窗体的大小发生改变而改变,符合我们的使用习惯. 绝对位置程序员以像素为单位指定每个小部件的位置和大小. 当 ...

  7. WPF知识点--自定义Button(ControlTemplate控件模板)

    ControlTemplate是一种控件模板,可以通过它自定义一个模板来替换掉控件的默认模板以便打造个性化的控件. ControlTemplate包含两个重要的属性:VisualTree 该模板的视觉 ...

  8. CAD参数绘制对齐标注(网页版)

    主要用到函数说明: _DMxDrawX::DrawDimAligned 绘制一个对齐标注.详细说明如下: 参数 说明 DOUBLE dExtLine1PointX 第一条界线开始点X值 DOUBLE ...

  9. MFCEditBox如何自动换行

    设置该EditBox属性: 1.Auto HScroll             False 2.OEM Convert           False 3.Want Return           ...

  10. vue工程化与路由router

    一.介绍     vue.js 是 目前 最火的前端框架,vue.js 兼具 angular.js 和 react.js 的优点,并剔除它们的缺点.并且提供了很多的周边配套工具 如vue-router ...