题目链接

问题分析

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

其实直接看题思路挺简单的。发现如果每种花都有无限多的话,问题变得十分简单,答案就是\(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. H.Holy Grail ( floyd )(The Preliminary Contest for ICPC Asia Nanjing 2019)

    题意: 给出一个有向图,再给出6条原来不存在的路径,让你在这6条路径上添加一个最小的数,使图不存在负环. 思路: 直接6遍 floyd 输出就行了. #include <bits/stdc++. ...

  2. 华为wlan配置流程及相关重要步骤AC配置

    本次介绍是AC+fitAP组网方式的重要步骤. 一.基础配置 1.规划好ac+ap的组网方式和转发方式.(本次以三层旁挂直接转发),规划管理vlan,业务vlan,与AC连接的vlan,以及他们接口的 ...

  3. MapReduce框架中的Shuffle机制

    Shuffle是map和reduce中间的数据调度过程,包括:缓存.分区.排序等. Shuffle数据调度过程: map task处理hdfs文件,调用map()方法,map task的collect ...

  4. IdentitiServser4 + Mysql实现Authorization Server

    Identity Server 4官方文档:https://identityserver4.readthedocs.io/en/latest/ 新建2个asp.net core 项目使用空模板 Aut ...

  5. java实现spark常用算子之map

    import org.apache.spark.SparkConf;import org.apache.spark.api.java.JavaRDD;import org.apache.spark.a ...

  6. es分数_score衰减函数

    1.按日期衰变 GET news/doc/_search { "query" : { "function_score": { "query" ...

  7. Delphi ListBox组件

  8. 标准C语言(5)

    无法预知的数字叫随机数,rand标准函数可以用来获得随机数,为了使用这个标准函数需要包含stdlib.h头文件 srand标准函数用来设置随机数种子,这个函数把一个整数作为种子使用不同的种子可以得到不 ...

  9. windows下前端开发环境配置

    nvm安装 多媒体布局 前端自动化构建工具,gulp nvm管理node的版本,npm是node的包管理工具 下载nvm安装包 https://github.com/coreybutler/nvm-w ...

  10. 【CF750E】New Year and Old Subsequence

    题目大意:给定一个长度为 N 的字符串,定义一个字串是"好的",当且仅当字串中含有一个 "2017" 的子序列,且不含有 "2016" 的子 ...