Discription

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<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1100005;
const int ha=1000000007;
int ci[33],tag[maxn],n,inv[33];
ll sum[maxn],S,ans=0; inline int add(int x,int y){
x+=y;
return x>=ha?x-ha:x;
} inline void init(){
ci[0]=1;
for(int i=1;i<=20;i++) ci[i]=ci[i-1]<<1;
inv[1]=1;
for(int i=2;i<=20;i++) inv[i]=-inv[ha%i]*(ll)(ha/i)%ha+ha;
} inline int C(int x,int y){
int an=1;
for(int i=1;i<=y;i++) an=an*(ll)(x-i+1)%ha*(ll)inv[i]%ha;
return an;
} inline void solve(){
tag[0]=1,sum[0]=0;
for(int i=0;i<ci[n];i++){
if(i) tag[i]=-tag[i^(i&-i)];
sum[i]=sum[i^(i&-i)]+sum[i&-i];
if(sum[i]<=S) ans=add(ans,add(tag[i]*C((S-sum[i]+n-1)%ha,n-1),ha));
}
} int main(){
init();
scanf("%d%I64d",&n,&S);
for(int i=0;i<n;i++) scanf("%I64d",sum+ci[i]),sum[ci[i]]++;
solve();
printf("%I64d\n",ans);
return 0;
}

Codeforces 451 E Devu and Flowers的更多相关文章

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

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

  2. 【Codeforces 258E】 Devu and Flowers

    [题目链接] http://codeforces.com/contest/451/problem/E [算法] 容斥原理 [代码] #include<bits/stdc++.h> usin ...

  3. Codeforces Round #258 (Div. 2) E. Devu and Flowers 容斥

    E. Devu and Flowers 题目连接: http://codeforces.com/contest/451/problem/E Description Devu wants to deco ...

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

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

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

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

  6. E. Devu and Flowers

    E. Devu and Flowers time limit per test 4 seconds memory limit per test 256 megabytes input standard ...

  7. CF451E Devu and Flowers 解题报告

    CF451E Devu and Flowers 题意: \(Devu\)有\(N\)个盒子,第\(i\)个盒子中有\(c_i\)枝花.同一个盒子内的花颜色相同,不同盒子的花颜色不同.\(Devu\)要 ...

  8. CF451E Devu and Flowers(容斥)

    CF451E Devu and Flowers(容斥) 题目大意 \(n\)种花每种\(f_i\)个,求选出\(s\)朵花的方案.不一定每种花都要选到. \(n\le 20\) 解法 利用可重组合的公 ...

  9. BZOJ1101 [POI2007]Zap 和 CF451E Devu and Flowers

    Zap FGD正在破解一段密码,他需要回答很多类似的问题:对于给定的整数a,b和d,有多少正整数对x,y,满足x<=a,y<=b,并且gcd(x,y)=d.作为FGD的同学,FGD希望得到 ...

随机推荐

  1. shell脚本,计算输入给定的数,判断最大值,最小值,总和?

    [root@localhost ~]# cat five.sh #!/bin/bash #任意输入5个数,判断最大值,最小值,总和 s= read -p "please input:&quo ...

  2. iOS UI 设计

    优设 http://www.uisdc.com Sketch http://www.sketchcn.com

  3. python网络数据采集 Tesseract

    使用chrome代替PhantomJS,selennium3不支持PhantomJS,编码用"utf-8",不然会报错.tesseract要添加TESSDATA_PREFIX环境变 ...

  4. docker参考文档

    docker 使用笔记 http://www.cnblogs.com/xguo/p/3829329.html docker数据存储 | 单线程 http://opjasee.com/2014/06/2 ...

  5. Linux 特殊权限位简介

    suid.guid suid 针对二进制命令或者程序,让其拥有root或者属主权限执行 一.setsuid : chmod 4755 二进制命令或者程序 chmod u+s   二进制命令或者程序 示 ...

  6. 《linux设备驱动开发详解》笔记——6字符设备驱动

    6.1 字符设备驱动结构 先看看字符设备驱动的架构: 6.1.1 cdev cdev结构体是字符设备的核心数据结构,用于描述一个字符设备,cdev定义如下: #include <linux/cd ...

  7. 细说unittest-1

    转自:https://www.jianshu.com/p/6c07be6d61dc 一.什么是unittest unittest是Python单元测试框架,类似于JUnit框架. unittest中有 ...

  8. 安卓启动图去除顶部title和状态栏

    1.在启动页的xml配置中,设置layout的id, <?xml version="1.0" encoding="utf-8"?> <Line ...

  9. 算法学习记录-图——最小路径之Floyd算法

    floyd算法: 解决任意两点间的最短路径的一种算法,可以正确处理有向图或负权的最短路径问题,同时也被用于计算有向图的传递闭包. 设为从到的只以集合中的节点为中间节点的最短路径的长度. 若最短路径经过 ...

  10. hdu2024

    这题目感觉不是很严谨,如果是关键字的话也是不能作为合法标识符的,但是这个不用检测,就算要检测也会很费劲,还得用字符串匹配,而且还得知道一共都有哪些关键字,太麻烦了,所以出题人原意就是检查大小写字母数字 ...