题目链接

问题分析

没有想到母函数的做法……

其实直接看题思路挺简单的。发现如果每种花都有无限多的话,问题变得十分简单,答案就是\(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的更多相关文章

  1. CF451E Devu and Flowers (隔板法 容斥原理 Lucas定理 求逆元)

    Codeforces Round #258 (Div. 2) Devu and Flowers E. Devu and Flowers time limit per test 4 seconds me ...

  2. Codeforces 451E Devu and Flowers(容斥原理)

    题目链接:Codeforces 451E Devu and Flowers 题目大意:有n个花坛.要选s支花,每一个花坛有f[i]支花.同一个花坛的花颜色同样,不同花坛的花颜色不同,问说能够有多少种组 ...

  3. E. Devu and Flowers

    E. Devu and Flowers time limit per test 4 seconds memory limit per test 256 megabytes input standard ...

  4. 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 ...

  5. CF451E Devu and Flowers 解题报告

    CF451E Devu and Flowers 题意: \(Devu\)有\(N\)个盒子,第\(i\)个盒子中有\(c_i\)枝花.同一个盒子内的花颜色相同,不同盒子的花颜色不同.\(Devu\)要 ...

  6. CF451E Devu and Flowers(容斥)

    CF451E Devu and Flowers(容斥) 题目大意 \(n\)种花每种\(f_i\)个,求选出\(s\)朵花的方案.不一定每种花都要选到. \(n\le 20\) 解法 利用可重组合的公 ...

  7. BZOJ1101 [POI2007]Zap 和 CF451E Devu and Flowers

    Zap FGD正在破解一段密码,他需要回答很多类似的问题:对于给定的整数a,b和d,有多少正整数对x,y,满足x<=a,y<=b,并且gcd(x,y)=d.作为FGD的同学,FGD希望得到 ...

  8. 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 ...

  9. Codeforces 451 E Devu and Flowers

    Discription Devu wants to decorate his garden with flowers. He has purchased n boxes, where the i-th ...

随机推荐

  1. java 如何编写多线程的代码

    线程是干活的所以线程一定是Thread,或者改线程实现Runnable接口多线程是竞争关系,所以多个线程竞争同一个资源,也就是同一个对象所以这个竞争对象发到Thread中即: // resources ...

  2. idea 设置自动生成注释

    idea新建类注释规则 /** @ProjectName: ${PROJECT_NAME} @Package: ${PACKAGE_NAME} @ClassName: ${NAME} @Descrip ...

  3. redis 学习(1)-- redis 安装与启动

    redis 学习(1)-- redis 安装与启动 redis 特性 关于 redis 的介绍网上已经有很多信息了,这里我就不在详细说明了.介绍一下几个鲜明特性: 1.速度快 官方称可以达到10W的q ...

  4. Git复习(二)之远程仓库、注册GitHub账号、SSH警告、使用GitHub

    远程仓库 Git是分布式版本控制系统,同一个Git仓库,可以分布到不同的机器上.怎么分布呢?最早,肯定只有一台机器有一个原始版本库,此后,别的机器可以“克隆”这个原始版本库,而且每台机器的版本库其实都 ...

  5. 基于bootstrap的分页插件

    之前做的分页,是自己后端写一堆代码,返回给前端页面显示,感觉比较繁重.不灵活.今天研究下基于bootstrap的做的插件,整理如下: 在使用bootstrap的插件的时候,需要导入一些css.js. ...

  6. web-CSS居中大全

    居中是我们使用css来布局时常遇到的情况.使用css来进行居中时,有时一个属性就能搞定,有时则需要一定的技巧才能兼容到所有浏览器,本文就居中的一些常用方法做个简单的介绍. 注:本文所讲方法除了特别说明 ...

  7. new angular 项目的工作区配置文件和应用源文件

    1.工作区配置文件 每个工作空间中的所有项目共享同一个 CLI 配置环境 .该工作空间的顶层包含着全工作空间级的配置文件.根应用的配置文件以及一些包含根应用的源文件和测试文件的子文件夹. 工作空间配置 ...

  8. 为SourceInsight添加多行注释功能菜单

    由于项目看代码主要使用的是Source Insight,习惯了其他编辑器的多行注释功能,对此感到很不习惯,查询网上程序,可以自行添加. 1.打开project,选择base项目中的utils.em,添 ...

  9. postgres日常操作

    1.启动pgsl数据库 [postgres@master ~]$ pg_ctl start [postgres@master data]$ pg_ctl -D /usr/local/pgsql/dat ...

  10. .Net Framework4.5中Asp.net mvc使用Singal R轮训实现导入进度条功能

    .Net Framework4.5中Asp.net mvc使用Singal R轮训实现导入进度条功能 我的项目需求是:在.net4.5中用mvc5实现上传xml文件,后台实时导入数据库时传到前台进度, ...