CodeForces451E Devu and Flowers
问题分析
没有想到母函数的做法……
其实直接看题思路挺简单的。发现如果每种花都有无限多的话,问题变得十分简单,答案就是\(s+n-1\choose n - 1\)。然后发现\(n\)只有\(20\),于是大力容斥一波就完事了。
参考代码
#include <cstdio>
const long long Max_n = 30;
const long long Mod = 1000000007;
long long n, s, f[ Max_n ];
void Exgcd( long long a, long long b, long long & x, long long & y ) {
if( b == 0LL ) { x = 1LL; y = 0LL; return; }
Exgcd( b, a % b, y, x );
y -= a / b * x;
return;
}
long long Inv( long long a ) {
long long x, y;
Exgcd( a, Mod, x, y );
if( x < 0 ) x += Mod;
return x;
}
long long C( long long n, long long m ) {
long long Ans = 1;
for( long long i = 1; i <= m; ++i ) Ans = Ans * ( ( n - i + 1 ) % Mod ) % Mod;
for( long long i = 1; i <= m; ++i ) Ans = Ans * Inv( i ) % Mod;
return Ans;
}
int main() {
scanf( "%lld%lld", &n, &s );
for( long long i = 1; i <= n; ++i ) scanf( "%lld", &f[ i ] );
long long Ans = 0;
for( long long i = 0; i < 1 << n; ++i ) {
long long t, Cnt = 0, Pos = s;
for( t = i; t; t >>= 1 ) if( t & 1 ) ++Cnt;
for( long long j = 1, t = i; t; t >>= 1, ++j ) if( t & 1 ) Pos -= f[ j ] + 1;
if( Pos < 0 ) continue;
Ans += ( Cnt & 1 ) ? -C( Pos + n - 1, n - 1 ) : C( Pos + n - 1, n - 1 );
Ans = ( Ans + Mod ) % Mod;
}
printf( "%lld\n", Ans );
return 0;
}
CodeForces451E Devu and Flowers的更多相关文章
- CF451E Devu and Flowers (隔板法 容斥原理 Lucas定理 求逆元)
Codeforces Round #258 (Div. 2) Devu and Flowers E. Devu and Flowers time limit per test 4 seconds me ...
- Codeforces 451E Devu and Flowers(容斥原理)
题目链接:Codeforces 451E Devu and Flowers 题目大意:有n个花坛.要选s支花,每一个花坛有f[i]支花.同一个花坛的花颜色同样,不同花坛的花颜色不同,问说能够有多少种组 ...
- E. Devu and Flowers
E. Devu and Flowers time limit per test 4 seconds memory limit per test 256 megabytes input standard ...
- 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 ...
- CF451E Devu and Flowers 解题报告
CF451E Devu and Flowers 题意: \(Devu\)有\(N\)个盒子,第\(i\)个盒子中有\(c_i\)枝花.同一个盒子内的花颜色相同,不同盒子的花颜色不同.\(Devu\)要 ...
- CF451E Devu and Flowers(容斥)
CF451E Devu and Flowers(容斥) 题目大意 \(n\)种花每种\(f_i\)个,求选出\(s\)朵花的方案.不一定每种花都要选到. \(n\le 20\) 解法 利用可重组合的公 ...
- BZOJ1101 [POI2007]Zap 和 CF451E Devu and Flowers
Zap FGD正在破解一段密码,他需要回答很多类似的问题:对于给定的整数a,b和d,有多少正整数对x,y,满足x<=a,y<=b,并且gcd(x,y)=d.作为FGD的同学,FGD希望得到 ...
- CodeForces-451E:Devu and Flowers (母函数+组合数+Lucas定理)
Devu wants to decorate his garden with flowers. He has purchased n boxes, where the i-th box contain ...
- Codeforces 451 E Devu and Flowers
Discription Devu wants to decorate his garden with flowers. He has purchased n boxes, where the i-th ...
随机推荐
- .Net Core 中使用NLog作为日志中间件
⒈安装相关依赖 NLog NLog.Web.AspNetCore ⒉在项目的根目录中创建NLog配置文件 <?xml version="1.0" encoding=" ...
- 2-SAT问题介绍求解 + 模板题P4782
(点击此处查看原题) 什么是2-SAT问题 sat 即 Satisfiability,意思为可满足,那么2-SAT表示一些布尔变量只能取true或者false,而某两个变量之间的值存在一定的关系(如: ...
- Django发送邮件和itsdangerous模块的配合使用
项目需求:用户注册页面注册之后,系统会发送一封邮件到用户邮箱,用户点击链接以激活账户,其中链接中的用户信息需要加密处理一下 其中激活自己邮箱的smtp服务的操作就不在加以说明,菜鸟教程上有非常清晰的讲 ...
- Hive 教程(一)-安装与配置解析
安装就安装 ,不扯其他的 hive 依赖 在 hive 安装前必须具备如下条件 1. 一个可连接的关系型数据库,如 Mysql,postgresql 等,用于存储元数据 2. hadoop,并启动 h ...
- eclipse 保存web.xml 和 loading description from 问题的解决
Eclipse 版本为 2019-06 (4.12.0) 发现开启的时候一直有loading description from *** ,这个loading description 是web项目加载 ...
- 25 Python之模块与包
一.模块 模块就是一个包含了python定义和申明的文件,文件名就是模块的名字加上.py的后缀/ 模块的分类: 1.使用python编写的py文件 2.已被编译位共享库或者DLL或 ...
- Axure(一)
axure1.原型工具 2.软件开发 1.可行性分析2.需求分析 产品经理(和甲方对接需求,) 乙方 -- 甲方 ps(专业性强,精美) 设计师 html(可变 ...
- 使输入框(input & textarea)变为只可读状态readonly="readonly",禁用输入框disabled="disabled"
使输入框变为只可读状态 readonly="readonly" <input class="select-city" placeholder=" ...
- 第二篇 HTML 常用元素及属性值
常用元素及属性值 先和同学了解下,一部分常用的元素,区别以及属性,常用在哪里. 标签是由左右尖括号抱起来的,由开始标签开始,再由结束标签结束,里面内容则是元素,比如:<div>< ...
- css3中单位rem与.less结合布局
rem是CSS3新增的一个相对单位(root em,根em),这个单位引起了广泛关注.这个单位与em有什么区别呢?区别在于使用rem为元素设定字体大小时,仍然是相对大小,但相对的只是HTML根元素. ...