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 ...
随机推荐
- thinkPHP模型before_insert新增前 before_update更新前 before_write写入前 区别
thinkPHP模型中有个save方法,可用于新增数据和修改数据,这里容易出现混淆. 经过调试: before_write,不管是插入新数据还是修改数据都会执行: before_insert,只有插入 ...
- Eslint报错整理与解决方法
1.‘Unexpected tab character’ 字面意思理解呢就是意想不到的制表符,当时出现的时候就是我习惯的使用Tab键去打空格,但是eslint默认不认可Tab,所以解决方法很简单: 在 ...
- Mac OS 下定制终端颜色
方法 有五种方法, 参考网站,我使用的是 Oh My Zsh 方案一:(通过 .bash_profile 文件自定制) 方案二:(也是修改 ~/.bash_profile) 方案三:(三方插件 Oh ...
- myBatis+Spring+SpringMVC框架面试题整理
myBatis+Spring+SpringMVC框架面试题整理(一) 2018年09月06日 13:36:01 新新许愿树 阅读数 14034更多 分类专栏: SSM 版权声明:本文为博主原创文章 ...
- 部署Dashboard,监控应用
部署web UI(dashboard)用于监控node资源 参见文档:https://blog.csdn.net/networken/article/details/85607593 官网:https ...
- 第二十一篇 jQuery 学习3 特效效果
jQuery 学习3 这节课主要是学习jQuery的动态效果. show()和hide()显示与隐藏方法,toggle()方法,fadeIn()谈入,fadeOut()谈出,slideDown() ...
- less 经典范例 bootstrap 的 less 版本 常用 less 代码
1. bootstrap 的 less 版本 2.less 文件分布 /*! * Bootstrap v3.3.7 (http://getbootstrap.com) * Copyright 2011 ...
- Delphi SpeedButton组件
- Delphi MaskEdit 组件
- golang连接activemq,发送接收数据
介绍 使用golang连接activemq发送数据的话,需要使用一个叫做stomp的包,直接go get github.com/go-stomp/stomp即可 代码 生产者 package main ...