传送门

解题思路:

假如只有 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. UVa 11085 - Back to the 8-Queens

    题目:给你一个棋盘上的八个皇后.每行一个.如今让他们互相不攻击,每一个皇后仅仅能竖着移动, 一次能够移动到本列的不论什么位置,问最少移动几步.能满足要求. 分析:搜索,八皇后.由于八皇后仅仅有92组解 ...

  2. 在Fedora18上配置个人的Hadoop开发环境

    在Fedora18上配置个人的Hadoop开发环境 1.    背景 文章中讲述了类似于"personalcondor"的一种"personal hadoop" ...

  3. Java并发编程 - Executor,Executors,ExecutorService, CompletionServie,Future,Callable

    一.Exectuor框架简介 Java从1.5版本开始,为简化多线程并发编程,引入全新的并发编程包:java.util.concurrent及其并发编程框架(Executor框架). Executor ...

  4. 生成不重复的随机数对(C/C++)

    1 #include <stdio.h> #include <algorithm> #include <stdlib.h> #include <time.h& ...

  5. POJ 1636 DFS+DP

    思路: 先搜索出来如果选这个点 其它哪些点必须选 跑个背包就好了 //By SiriusRen #include <cstdio> #include <cstring> #in ...

  6. js library 集合

    js library 集合 查看已经开源的js library https://cdnjs.com/

  7. Httpd 文件服务器的搭建

    服务器信息 系统: CentOS 安装操作 安装 httpd 直接通过 yum 安装: yum install httpd 安装完成之后,可以检查版本: http 查看版本 httpd -versio ...

  8. android+myeclipse+mysql自定义控件下拉框的数据绑定

    原创作品,允许转载,转载时请务必声明作者信息和本声明.http://www.cnblogs.com/zhu520/p/8031936.html 本人小白,那个大神看到有问题可指出,谢谢.... 这个是 ...

  9. H+后台主题UI框架---整理

    本篇文章是对H+这种框架进行整理,顺便了解一下标准的代码规范的写法. 一.表单: 1).下面是一个基本表单: 现在来看这个表单的结构: 1.整个表单的外框结构是一个div,至于padding和marg ...

  10. 【原生JS组件】javascript 运动框架

    大家都知道JQuerry有animate方法来给DOM元素进行运动,CSS3中也有transition.transform来进行运动.而使用原生的Javascript来控制元素运动,须要写非常多运动的 ...