传送门

解题思路:

假如只有 s 束花束并且不考虑 f ,那么根据隔板法的可重复的情况时,这里的答案就是

假如说只有一个 f 受到限制,其不合法时一定是取了超过 f 的花束

那么根据组合数,我们仍然可以算出其不合法的解共有:

最后,由于根据容斥,减两遍的东西要加回来,那么含有偶数个 f 的项为正,奇数个时为负。

答案就是:

搜索答案,使用Lucas定理,计算组合数上下约去。

代码:

 #include<cstdio>
#include<cstring>
#include<algorithm>
typedef long long lnt;
const lnt mod=(lnt)(1e9+);
int n;
lnt s,ans;
lnt f[];
lnt ksm(lnt x,lnt y)
{
lnt ans=;
while(y)
{
if(y&)
ans=ans*x%mod;
x=x*x%mod;
y=y/;
}
return ans;
}
lnt Lucas(lnt n,lnt m)
{
if(n<mod&&m<mod)
{
if(n<m) return ;
if(n==m)return ;
if(m==)return ;
lnt nj=,mj=;
lnt a=n-m,b=m;
if(a>b)
std::swap(a,b);
lnt i=b+;
while(i<=n)
{
nj=(nj*i)%mod;
i++;
}
i=;
while(i<=a)
{
mj=(mj*i)%mod;
i++;
}
return ksm(mj,mod-)*nj%mod;
}
return Lucas(n%mod,m%mod)*Lucas(n/mod,m/mod)%mod;
}
lnt dle(lnt x)
{
return (((&x)^)<<)-;
}
void dfs(int p,int l,lnt sum)
{
if(p==n+)
{
ans=(ans+dle(l)*Lucas(s-sum+n-,n-))%mod;
return ;
}
dfs(p+,l,sum);
dfs(p+,l+,sum+f[p]+);
return ;
}
int main()
{
scanf("%d%I64d",&n,&s);
for(int i=;i<=n;i++)
scanf("%I64d",&f[i]);
ans=;
dfs(,,);
printf("%I64d\n",(ans%mod+mod)%mod);
return ;
}

Codeforces 451 E. Devu and Flowers(组合数学,数论,容斥原理)的更多相关文章

  1. Codeforces 451 E Devu and Flowers

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

  2. 【Codeforces 258E】 Devu and Flowers

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

  3. CF451E Devu and Flowers (组合数学+容斥)

    题目大意:给你$n$个箱子,每个箱子里有$a_{i}$个花,你最多取$s$个花,求所有取花的方案,$n<=20$,$s<=1e14$,$a_{i}<=1e12$ 容斥入门题目 把取花 ...

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

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

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

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

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

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

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

  8. E. Devu and Flowers

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

  9. CF451E Devu and Flowers 解题报告

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

随机推荐

  1. Yocto tips (10): Yocto hellworld 加入一个软件包

    Yocto中一个软件包是放在bb文件里的,然后非常多的bb文件集成一个recipe(配方),然后很多的recipe又组成一个meta layer.因此,要加入一个包事实上就是在recipe以下加入一个 ...

  2. Create the Data Access Layer

    https://docs.microsoft.com/en-us/aspnet/web-forms/overview/getting-started/getting-started-with-aspn ...

  3. 阿里云aliyunlive视频直播,设置元素浮在视频上方

    视频直播,视频是可以看到了.但是还需要其他的元素,比如聊天内容,小礼物效果,观看人员列表等等.怎样让其他的元素,浮在视频上方呢? 解决方案,通过打开一个frame层,设置body的背景为透明的. 新的 ...

  4. Gym - 100625J Jailbreak 最短路+搜索

    http://codeforces.com/gym/100625/attachments/download/3213/2013-benelux-algorithm-programming-contes ...

  5. css3 文字溢出 换行实现方案

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

  6. HTML5新增的一些特性

    HTML现在已经不是SGML的子集,主要是关于图像,位置,储存,多任务等功能的增加. .绘画canvas: .用于媒介回放的video: Ogg是带有Theora视频编码和Vorbis音频编码的文件: ...

  7. DedeCMS版权信息SQL命令删除

    dedecms织梦系统底部会自动带有官方链接power by dedecms字样,很多新用户想去除官方的链接,底部调用标签为{dede:global.cfg_poweby/},方法很多,但不鼓励大家删 ...

  8. 【Henu ACM Round#14 A】Vitaly and Night

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 连续两个如果不全是0就递增cnt [代码] #include <bits/stdc++.h> using namespa ...

  9. HDU 3911 Black And White

    Black And White Time Limit: 3000ms Memory Limit: 32768KB This problem will be judged on HDU. Origina ...

  10. from disk cache 与 from memory cache

    webkit资源的分类 webkit的资源分类主要分为两大类:主资源和派生资 http状态码 200 from memory cache 不访问服务器,直接读缓存,从内存中读取缓存.此时的数据时缓存到 ...