首页 技术 正文
技术 2022年11月21日
0 收藏 832 点赞 2,927 浏览 1618 个字

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;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,992
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,506
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,767
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844