E. Devu and Flowers

题目连接:

http://codeforces.com/contest/451/problem/E

Description

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

Sample Input

2 3

1 3

Sample Output

2

Hint

题意

有n个盒子,然后每个盒子有f[i]个,你需要拿出来s个球,问你一共有多少种选择。

题解:

题目改一下,改成你有s个球,要放进n个盒子,问一共有多少种方案。

隔板法去放就好了。

再容斥处理那个f[i]

代码

#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define LL long long
using namespace std;
LL qmod(LL a,LL b)
{
LL res=1;
if(a>=MOD)a%=MOD;
while(b)
{
if(b&1)res=res*a%MOD;
a=a*a%MOD;
b>>=1;
}
return res;
}
LL invmod[50];
LL C(LL n,LL m)
{
if(n<m)return 0;
LL ans=1;
for(int i=1;i<=m;++i)
ans=(n-i+1)%MOD*ans%MOD*invmod[i]%MOD;
return ans;
}
LL f[30],n,s;
LL ans;
void gao(int now,LL sum,int flag)
{
if(sum>s)return ;
if(now==n)
{
ans+=flag*C(s-sum+n-1,n-1);
ans%=MOD;
return ;
}
gao(now+1,sum,flag);
gao(now+1,sum+f[now]+1,-flag);
}
int main() {
for(int i=1;i<=20;++i)
invmod[i]=qmod(i,MOD-2);
cin>>n>>s;
for(int i=0;i<n;++i)
cin>>f[i];
ans=0;
gao(0,0,1);
cout<<(ans%MOD+MOD)%MOD<<endl;
return 0;
}

Codeforces Round #258 (Div. 2) E. Devu and Flowers 容斥的更多相关文章

  1. Codeforces Round #258 (Div. 2)E - Devu and Flowers

    题意:n<20个箱子,每个里面有fi朵颜色相同的花,不同箱子里的花颜色不同,要求取出s朵花,问方案数 题解:假设不考虑箱子的数量限制,隔板法可得方案数是c(s+n-1,n-1),当某个箱子里的数 ...

  2. Codeforces Round #330 (Div. 2) B. Pasha and Phone 容斥定理

    B. Pasha and Phone Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/pr ...

  3. Codeforces Round #428 (Div. 2) D. Winter is here 容斥

    D. Winter is here 题目连接: http://codeforces.com/contest/839/problem/D Description Winter is here at th ...

  4. Codeforces Round #330 (Div. 2)B. Pasha and Phone 容斥

    B. Pasha and Phone   Pasha has recently bought a new phone jPager and started adding his friends' ph ...

  5. Codeforces Round #619 (Div. 2)C(构造,容斥)

    #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; int main(){ ios::syn ...

  6. Codeforces Round #258 (Div. 2)[ABCD]

    Codeforces Round #258 (Div. 2)[ABCD] ACM 题目地址:Codeforces Round #258 (Div. 2) A - Game With Sticks 题意 ...

  7. Codeforces Round #258 (Div. 2) 小结

    A. Game With Sticks (451A) 水题一道,事实上无论你选取哪一个交叉点,结果都是行数列数都减一,那如今就是谁先减到行.列有一个为0,那么谁就赢了.因为Akshat先选,因此假设行 ...

  8. Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理

    Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理 [Problem Description] 在\(n\times n\) ...

  9. CF451E Devu and Flowers(容斥)

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

随机推荐

  1. .NET面试题系列(四)计算机硬件知识

    计算机的硬件组成 总线:贯穿整个系统的是一组电子管道(其实就是传输数据的线路),也就是总线.总线传送的是字,字的大小与系统相关,比如在32位操作系统当中, 一个字是4个字节. I/O设备:I/O设备是 ...

  2. H5 Day2 练习

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. Ubuntu django+nginx 搭建python web服务器文件日志

    uwsgi 配置文件 [uwsgi] http-socket = 127.0.0.1:8080 # 项目目录 chdir=/home/ubuntu/mkweb # 指定项目的application m ...

  4. 使用Sysmon和Splunk探测网络环境中横向渗透

    当前很难在网络中探测攻击者横向渗透,其中原因有很难获取必要的日志和区别正常与恶意行为.本篇文章介绍通过部署Sysmon并将日志发送到SIEM来探测横向渗透. 工具: Sysmon + Splunk l ...

  5. LTE:eMBMS架构

    一个MBSFN区域是由一个或多个传输相同内容的小区组成的特殊区域.如图1所示,小区8和9都属于MBSFN区域C.一个MBSFN区域可由多个小区组成,一个小区也可以属于多个(至多8个,从36.331中的 ...

  6. Spring bean 配置

    1.传统的创建对象的方式:JedisMall tardition=new JedisMall(); 这样是在程序运行时创建,表示当前模块已经不知不觉和new出的对象耦合了,而我们通常都是更高层次的抽象 ...

  7. Android Studio之代码提示快捷键冲突设置

    1.原代码提示快捷键为:Ctrl+空格,与Windows输入法冲突,所以将代码提示快捷键设置为:Ctrl+反斜杠.

  8. MYSQL数据库链接层- SUMMER-SQL

    2015年3月31日 18:27:34 最后编辑: 2016年4月17日 00:22:00 星期日 最后编辑: 2018-4-25 16:58:44 星期三 最新代码: https://gitee.c ...

  9. javaweb笔记四

    得到表单数据:1.String str = request.getParameter(String)//根据表单名得到表单值,如果是多个同名的键值,返回第一个值.2.String[] str= req ...

  10. EFCore CodeFirst 适配数据库

    EF6中可以直接根据代码模型生成数据库Database.SetInitializer即可 在EFCore中如何实现呢? 这项功能放在了DatabaseFacade对象中,传入数据库上下文对象实例化到一 ...