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 ...
随机推荐
- ATM机小程序
用规范化项目录的格式模拟一个ATM系统. 项目功能: 登录(可支持多个账户(非同时)登录) 注册 查看余额 存钱 转账(给其他用户转钱) 查看账户流水 退出 提供的思路:ATM直译就是取款机,但是咱们 ...
- float详解
先上一个简单示例,了解一下float的使用 <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- C# 面向对象4 构造函数
构造函数 1.构造函数用来创建对象,并且可以在构造函数中对对象进行初始化. (给对象的每个属性依次的赋值) 2.构造函数是用来创建对象的特殊方法: 1.方法名和类名一样. 2.没有返回值,连void都 ...
- Jquery 控制table中的checkbox 相关选中事件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 无障碍开发(三)之ARIA aria-***属性值
aria-***属性值
- Mysql学习(二)之通过homebrew安装mysql后,为什么在系统偏好设置里没有mysql
原因 用brew install packagename是用来安装命令行工具的,一般不可能影响到图形界面. mysql官方文档是通过dmg文件安装的: The MySQL Installation P ...
- 2018年4月份,阿里最新的java程序员面试题目,仅供参考。
目录 技术一面(23问) 技术二面(3大块) 性能优化(21点) 项目实战(34块) JAVA方向技术考察点(15点) JAVA开发技术面试中可能问到的问题(17问) 阿里技术面试1 1.Java I ...
- shell条件嵌套(if条件语句)
[注意1]:和Java.PHP等语言不一样,sh的流程控制不可为空,如: 代码如下: <?php if (isset($_GET["q"])) { search(q); } ...
- zabbix的nginx监控+邮件报警
nginx监控 下载nginx的监控模板
- ros 封ip,域名,端口,重定向
1.封IP / ip firewall filter add chain=forward dst-address=192.168.0.1(想要封的IP) action=drop comment=&qu ...