E. Devu and Flowers
time limit per test

4 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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).

Examples
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}.

这个题是就是容斥原理的东西, 因为观察到N的范围就是20,S的范围就是就是很大的,所以要是在f[i]没有时间限制的情况的时候

然后就是根据常用的隔板法的原理,然后就是可以得到 x1+x2+x3+x4-----xn =s;

然后的话因为x1---xn的取值有可能是0,那么的话我得到的结果就和隔板法的结果不一样了,那这样的哈我就把所有的值都加1,然后就可以了。

还有的话我们就会用到容斥原理,然后就是假设

|!A1n!A2.....n!An| = N-|A1UA2UA3....UAn| ====》 我们假设!A== 1<=x<=f[i]+1;  那么A的话就是  f[i]+1<x<=sum;

这样子的话区间的长度就是 sum-f[i]-1  就是从1---sum-f[i]-1;

然后的话应该就可以了,,,,,

E. Devu and Flowers的更多相关文章

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

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

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

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

  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. CF451E Devu and Flowers 解题报告

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

  5. CF451E Devu and Flowers(容斥)

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

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

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

  7. Codeforces 451 E Devu and Flowers

    Discription Devu wants to decorate his garden with flowers. He has purchased n boxes, where the i-th ...

  8. CodeForces-451E:Devu and Flowers (母函数+组合数+Lucas定理)

    Devu wants to decorate his garden with flowers. He has purchased n boxes, where the i-th box contain ...

  9. Devu and Flowers lucas定理+容斥原理

    Devu wants to decorate his garden with flowers. He has purchased n boxes, where the i-th box contain ...

随机推荐

  1. lpc1768ADC使用

    Lpc1768内置有一个ad外设,该外设有八路复用输入,所以,可以同时接八路ad设备,同时还支持触发转换模式,由外部端口进行ad触发,ad转换完成之后可以产生中断 Lpc1768支持的转换模式有两种, ...

  2. 我推荐的一些iOS开发书单

    文/叶孤城___(简书作者)原文链接:http://www.jianshu.com/p/2fa080673842著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 上次发了一下比较不错的i ...

  3. MVC笔记1

    测试实体类 public class Test { public int id{get;set;} [Required(ErrorMessage="不能为空喔")] [String ...

  4. 1.TCP/IP基本概念

    为什么会有TCP/IP协议 在世界上各地,各种各样的电脑运行着各自不同的操作系统为大家服务,这些电脑在表达同一种信息的时候所使用的方法是千差万别.就好像圣经中上帝打乱了各地人的口音,让他们无法合作一样 ...

  5. wildfly 如何设置外网访问

    wildfly的默认配置是不支持外网访问的, 要想实现外网访问需要修改standalone.xml配置文件. 配置文件所在路径:wildfly/standalone/configuration/sta ...

  6. BUG--tomcat更改目录失败

    1.问题描述 按照通用的做法,tomcat可以配置运行的网站目录.但是配置后不能正确运行. 配置过程如:http://www.cnblogs.com/SimonGao/p/4905887.html 2 ...

  7. Android性能优化(一)之启动加速35%

    一.前言 随着项目版本的迭代,App的性能问题会逐渐暴露出来,而好的用户体验与性能表现紧密相关,从本篇文章开始,我将开启一个Android应用性能优化的专题,从理论到实战,从入门到深挖,手把手将性能优 ...

  8. Android组件生命周期(三)

    Android系统试图尽可能长地保持一个应用程序进程,但是当内存低时它最终还是需要移除旧的进程.为了决定保持哪个进程及杀死哪个进程,Android将每个进程放入一个基于运行于其中的组件的重要性等级和这 ...

  9. redhat6 + 11G DG部署

    在主库中netca配置 [oracle@HE3dbs]$ cat /u01/app/oracle/product/11gr2/db_1/network/admin/listener.ora #list ...

  10. 大数据时代的杀手锏----Tachyon

    一.Tachyon系统的简介 Tachyon是一个分布式内存文件系统,可以在集群里以访问内存的速度来访问存在tachyon里的文件.把 Tachyon是架构在最底层的分布式文件存储和上层的各种计算框架 ...