Codeforces 451 E. Devu and Flowers(组合数学,数论,容斥原理)
传送门
解题思路:
假如只有 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(组合数学,数论,容斥原理)的更多相关文章
- Codeforces 451 E Devu and Flowers
Discription Devu wants to decorate his garden with flowers. He has purchased n boxes, where the i-th ...
- 【Codeforces 258E】 Devu and Flowers
[题目链接] http://codeforces.com/contest/451/problem/E [算法] 容斥原理 [代码] #include<bits/stdc++.h> usin ...
- CF451E Devu and Flowers (组合数学+容斥)
题目大意:给你$n$个箱子,每个箱子里有$a_{i}$个花,你最多取$s$个花,求所有取花的方案,$n<=20$,$s<=1e14$,$a_{i}<=1e12$ 容斥入门题目 把取花 ...
- Devu and Flowers lucas定理+容斥原理
Devu wants to decorate his garden with flowers. He has purchased n boxes, where the i-th box contain ...
- 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 ...
- Codeforces 451E Devu and Flowers(容斥原理)
题目链接:Codeforces 451E Devu and Flowers 题目大意:有n个花坛.要选s支花,每一个花坛有f[i]支花.同一个花坛的花颜色同样,不同花坛的花颜色不同,问说能够有多少种组 ...
- CF451E Devu and Flowers (隔板法 容斥原理 Lucas定理 求逆元)
Codeforces Round #258 (Div. 2) Devu and Flowers E. Devu and Flowers time limit per test 4 seconds me ...
- E. Devu and Flowers
E. Devu and Flowers time limit per test 4 seconds memory limit per test 256 megabytes input standard ...
- CF451E Devu and Flowers 解题报告
CF451E Devu and Flowers 题意: \(Devu\)有\(N\)个盒子,第\(i\)个盒子中有\(c_i\)枝花.同一个盒子内的花颜色相同,不同盒子的花颜色不同.\(Devu\)要 ...
随机推荐
- snowflake算法
snowflake算法思考 缘起 为什么会突然谈到分布式唯一id呢?原因是最近在准备使用RocketMQ,看看官网介绍: 一句话,消息可能会重复,所以消费端需要做幂等.为什么消息会重复后续Rocket ...
- Centos7 网络出错(failed to start LSB: Bring up/down networking )
这是我更换了VM虚拟机内存,重启后无法连接网络. 然后这是因为NetworkManager.service这个程序造成 解决方法: systemctl disable NetworkManager.s ...
- Weka中数据挖掘与机器学习系列之Exploer界面(七)
不多说,直接上干货! Weka的Explorer(探索者)界面,是Weka的主要图形化用户界面,其全部功能都可通过菜单选择或表单填写进行访问.本博客将详细介绍Weka探索者界面的图形化用户界面.预处理 ...
- P1328 生活大爆炸版石头剪刀布
题目描述 石头剪刀布是常见的猜拳游戏:石头胜剪刀,剪刀胜布,布胜石头.如果两个人出拳一样,则不分胜负.在<生活大爆炸>第二季第8 集中出现了一种石头剪刀布的升级版游戏. 升级版游戏在传统的 ...
- UltraEdit Companion Utility
UltraEdit Companion Utility 配色组件 http://www.danielwmoore.com/extras/index.php?action=downloads;sa=vi ...
- javascript“类”与继承总结
http://haorooms.com/post/js_jc_lei2
- AIX 软件包结构
AIX installp软件包结构 1. usr部分 2. / (root)部分 3. share部分 AIX 为了实现在客户机 / 服务器环境下安装的灵活性将安装包划分为 usr 部分 .r ...
- Node书签
1.开源项目 [译]过去一年25个惊人的开源Node.js项目(2018版) 百度网盘下载助手
- 参考分享《Python深度学习》高清中文版pdf+高清英文版pdf+源代码
学习深度学习时,我想<Python深度学习>应该是大多数机器学习爱好者必读的书.书最大的优点是框架性,能提供一个"整体视角",在脑中建立一个完整的地图,知道哪些常用哪些 ...
- 在idea 中使用try catch
ctrl+alt + t 选中代码,按快捷键可直接try catch 此段代码