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\)要 ...
随机推荐
- 数据库中的Convert
https://docs.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql Conversion failed ...
- 4.菜鸟教你一步一步开发 web service 之 axis 客户端创建
转自:https://blog.csdn.net/shfqbluestone/article/details/37723517 在上个教程中我们创建了一个 axis 服务端的 web service ...
- Python(九) Python的高级语法与用法
本章节我们揭开Python进阶部分的高级特性,详细讲解枚举.闭包,并对函数式编程做出介绍 一. 枚举其实是一个类 from enum import Enum #枚举类 class VIP(Enum): ...
- 170703 锐姿公司winserver2012 标准版安装过程
背景: 锐姿公司一台服务器,配置为:X3650M5 8871 E5 2620V4 32G 双电源 3*1T raid5 . 原系统由供应商(日闹)上家安装,在安装好的SQL2008,到 ...
- Python正则表达式初识(九)
继续分享Python正则表达式的基础知识,今天给大家分享的特殊字符是[\u4E00-\u9FA5],这个特殊字符最好能够记下来,如果记不得的话通过百度也是可以一下子查到的. 该特殊字符是固定的写法,其 ...
- LG Gram 2018 z980 白
因为今年8代处理器i5的双核变成了四核,感觉是个换电脑的好时机,本来打算买macbook,但是6月的发布会并没有发布,于是开始寻找一些比较有特点的笔记本电脑. 了解了这样一款笔记本 LG GRAM 1 ...
- SSH框架的多表查询(方法二)
必须声明本文章==>http://www.cnblogs.com/zhu520/p/7773133.html 一:在前一个方法(http://www.cnblogs.com/zhu520/p ...
- Activiti工作流(4):编写一个HelloWorld
版权声明:本文为博主原创文章,未经博主允许不得转载. 1.使用eclipse的activiti插件画流程图 在resource文件夹下新建一个工作流diagram 右键——new——other...— ...
- Intersection between a 2d line and a conic in OpenCASCADE
Intersection between a 2d line and a conic in OpenCASCADE eryar@163.com Abstract. OpenCASCADE provid ...
- android定时操作
Timer: 代码: Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { ...