传送门

解题思路:

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

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

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

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

答案就是:

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

代码:

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. typedef long long lnt;
  5. const lnt mod=(lnt)(1e9+);
  6. int n;
  7. lnt s,ans;
  8. lnt f[];
  9. lnt ksm(lnt x,lnt y)
  10. {
  11. lnt ans=;
  12. while(y)
  13. {
  14. if(y&)
  15. ans=ans*x%mod;
  16. x=x*x%mod;
  17. y=y/;
  18. }
  19. return ans;
  20. }
  21. lnt Lucas(lnt n,lnt m)
  22. {
  23. if(n<mod&&m<mod)
  24. {
  25. if(n<m) return ;
  26. if(n==m)return ;
  27. if(m==)return ;
  28. lnt nj=,mj=;
  29. lnt a=n-m,b=m;
  30. if(a>b)
  31. std::swap(a,b);
  32. lnt i=b+;
  33. while(i<=n)
  34. {
  35. nj=(nj*i)%mod;
  36. i++;
  37. }
  38. i=;
  39. while(i<=a)
  40. {
  41. mj=(mj*i)%mod;
  42. i++;
  43. }
  44. return ksm(mj,mod-)*nj%mod;
  45. }
  46. return Lucas(n%mod,m%mod)*Lucas(n/mod,m/mod)%mod;
  47. }
  48. lnt dle(lnt x)
  49. {
  50. return (((&x)^)<<)-;
  51. }
  52. void dfs(int p,int l,lnt sum)
  53. {
  54. if(p==n+)
  55. {
  56. ans=(ans+dle(l)*Lucas(s-sum+n-,n-))%mod;
  57. return ;
  58. }
  59. dfs(p+,l,sum);
  60. dfs(p+,l+,sum+f[p]+);
  61. return ;
  62. }
  63. int main()
  64. {
  65. scanf("%d%I64d",&n,&s);
  66. for(int i=;i<=n;i++)
  67. scanf("%I64d",&f[i]);
  68. ans=;
  69. dfs(,,);
  70. printf("%I64d\n",(ans%mod+mod)%mod);
  71. return ;
  72. }

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. 使用ThoughtWorks.QRCode生成二维码

    新建Windows应用程序,加入引用ThoughtWorks.QRCode.dll,编写代码生成二维码. using System; using System.Drawing; using Syste ...

  2. Mahout-HashMap的进化版FastByIdMap

    FastByIdMap是基于散列的.在处理冲突时是线性探測而非分离链接,这样就不必为每个条目添加一个Map.Entry对象.从而节省内存开销. 以下代码是一个线性探測Map的Demo: package ...

  3. Thumb指令集与ARM指令集的差别

    Thumb指令集          Thumb指令能够看做是ARM指令压缩形式的子集.是针对代码密度[1]的问题而提出的.它具有16为的代码密度.Thumb不是一个完整的体系结构,不能指望处理程序仅仅 ...

  4. UE4的JSON读写方式&lt;一&gt;

    声明:全部权利保留. 转载必须说明出处:http://blog.csdn.net/cartzhang/article/details/41009343 UE4的Json的解析博客地址: http:// ...

  5. 79.express里面的app.configure作用

    以下摘自 express 3.0 的 文档 app.configure([env], callback) Conditionally invoke callback when env matches ...

  6. Android 使用Retrofit获取JSON数据

    在大家使用网络请求的时候,往往会出现一种情况:需要拿到服务器返回来的JSON字符串,而Retrofit会默认将Json解析,而又没有直接暴露出拿到Json字符串的方法: 今天测接口的时候,发现当数据正 ...

  7. 清空/var/adm/wtmp 文件内容

    清/var/adm/wtmp 文件内容 用于显示登录系统和重启机器的情况 /var/adm/wtmp文件过大. 可用du -sm /var/adm/wtmp查看 cat /dev/null>/v ...

  8. LINUX中,find结合grep正则表达式,快速查找代码文件。

    ###目的###LINUX中,find结合grep正则表达式快速查找代码. 例如经常有需求:查找当前目录下所有.h文件中,"public开头,中间任意字符,以VideoFrameReceiv ...

  9. Pycharm在Ubuntu14.04中的基本使用指南

    前几天给大家分享了:如何在VMware虚拟机中安装Ubuntu14.04系统.今天给大家分享一下在Ubuntu14.04中如何简单的使用Pycharm.1.启动Pycharm,将进入Pycharm的启 ...

  10. [COI2007] Patrik 音乐会的等待 单调栈

    Code: #include<cstdio> #include<algorithm> #include<iostream> #include<cstring& ...