Codeforces 451 E Devu and Flowers
来源:互联网 发布:新网域名如何解析 编辑:程序博客网 时间:2024/06/05 11:10
原链接http://blog.csdn.net/ccsu_001/article/details/38170939
大致题意:
从n个盒子里面取出s多花,每个盒子里面的花都相同,并且每个盒子里面花的多数为f[i],求取法总数。
解题思路:
我们知道如果n个盒子里面花的数量无限,那么取法总数为:C(s+n-1, n-1) = C(s+n-1, s)。
可以将问题抽象成:x1+x2+...+xn = s, 其中0<=xi <= f[i],求满足条件的解的个数。
两种方法可以解决这个问题:
方法一:这个问题的解可以等价于:mul = (1+x+x^2+...+x^f[1])*(1+x+x^2+...+x^f[2])*...*(1+x+x^2+...+x^f[n])中x^s项的系数。而 (1+x+x^2+...+x^f[i]) = (1-x^(1+f[i]))/(1-x),那么mul = (1-x^(1+f[1]))*(1-x^(1+f[2]))*...*(1-x^(1+f[n]))*(1-x)^(-n)。
对于 (1-x^(1+f[1]))*(1-x^(1+f[2]))*...*(1-x^(1+f[n]))这部分的系数,由于n很小,直接暴力(2^n)枚举计算各项的系数。
对于(1-x)^(-n)的系数,(1-x)^(-n) = (1/(1-x))^n, 而1/(1-x) = 1 + x + x^2 + ... + x^n + ...,无穷级数,那么(1-x)^(-n) = (1+x+x^2+...+x^m+...)^n,要求这个式子x^s项的系数,就相当于从n个盒子(花的数量无限)里面去s朵花,求取法总数。于是(1-x)^(-n)中x^s项的系数为:C(s+n-1, n-1)。
知道这两部分的系数以后问题就迎刃而解了。
方法二:容斥原理。设A1 = {x1 >= f[1]+1}, A2 = {x2 >= f[2]+1}, ..., An = {xn >= f[n]+1}, 全集S = (n+s-1, s)。那么问题的解集为:全集减去不符合条件的解集(某个Ai为真), 不符合条件的解集可以用容斥原理来解决,即:。
暴力枚举(2^n)Ai的状态,如果Ai为真,则s -= (f[i]+1);那么这种状态下,解的为题相当于从n个盒子里面取s(减去该状态下所有f[i]+1以后的值)朵花,盒子花的数目没有限制,解的个数为C(s+n-1, n-1)。
- Codeforces 451 E Devu and Flowers
- codeforces 451 E Devu and Flowers
- 451 E. Devu and Flowers
- Codeforces 451E Devu and Flowers(容斥原理)
- codeforces 451E Devu and Flowers (容斥原理)
- codeforces 451E. Devu and Flowers 组合数+容斥
- CF 451E Devu and Flowers
- Codeforces#258 (Div.2) E - Devu and Flowers 容斥
- Codeforces#258 (Div.2) E - Devu and Flowers
- Codeforces #258 Div.2 E Devu and Flowers
- Codeforces Round #258 (Div. 2)E. Devu and Flowers
- codeforces #451E Devu and Flowers 不定方程解的个数+lucas定理
- CodeForces 451E Devu and Flowers(容斥原理+组合数学+状态压缩)
- [Codeforces 451E] Devu and Flowers (母函数+lucas定理)
- Codeforces 451E Devu and Flowers (组合数学+容斥+Lucas)
- codeforces 451E. Devu and Flowers (容斥原理+组合数学)
- Codeforces 451E Devu and Flowers 容斥原理暴力+Lucas定理
- codeforces 451E Devu and Flowers(容斥原理,Lucas,dfs,隔板法)
- Linux下实现秒级定时任务的两种方案(crontab 每秒运行)
- !!!IP地址转换
- Autodesk Vred 2016
- 15电气郄慧敏vb作业3红糖水白糖水的交换
- Fragment类
- Codeforces 451 E Devu and Flowers
- 买卖股票收益最大问题
- MAC OS 配置android环境
- 白话经典算法系列之六 快速排序 快速搞定
- 2016年3月小结
- 自定义dialog的宽度充满整个屏幕宽度的问题
- 进程,线程之间易混淆的几个问题
- POP弹性动画效果
- 获取手机总内存以及格式转化