题解:

如果没有限制每一种花有多少,那么就是简单的排列组合问题。

那么我们强制让一些花一定都要选。

暴力搜索,然后组合数(逆元)

采用容斥原理来计算最后的答案

代码:

#include<bits/stdc++.h>
using namespace std;
const int M=1e9+;
typedef long long ll;
ll i,j,k,l,t,n,m,ans,a[],er[],bz,sum;
ll ksm(ll x,ll y)
{
ll z=;
for(;y;y/=,(x*=x)%=M)
if(y&)(z*=x)%=M;
return z;
}
ll js(ll x,ll y)
{
if(x<y)return ;
ll a=,b=,i;
if(y<x-y)y=x-y;
for (int i=y+;i<=x;i++)a=a*i%M;
for (int i=;i<=x-y;i++)b=b*i%M;
return a*ksm(b,M-)%M;
}
ll c(ll x,ll y)
{
if(!y)return ;
return c(x/M,y/M)*js(x%M,y%M)%M;
}
int main()
{
scanf("%lld%lld",&n,&m);
for (int i=;i<=n;i++)scanf("%lld",&a[i]);
for (int i=;i<(<<n);i++)
{
bz=;sum=m;
for (int j=;j<=n;j++)
if(i&(<<(j-)))
{
bz*=-;
sum-=a[j]+;
}
if(sum<)continue;
(ans+=bz*c(n+sum-,n-))%=M;
}
ans=(ans+M)%M;
printf("%lld\n",ans);
}

51nod1269Devu 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. poj 3262 Protecting the Flowers

    http://poj.org/problem?id=3262 Protecting the Flowers Time Limit: 2000MS   Memory Limit: 65536K Tota ...

  3. Codeforces Round #381 (Div. 2)B. Alyona and flowers(水题)

    B. Alyona and flowers Problem Description: Let's define a subarray as a segment of consecutive flowe ...

  4. poj1157LITTLE SHOP OF FLOWERS

    Description You want to arrange the window of your flower shop in a most pleasant way. You have F bu ...

  5. CF459B Pashmak and Flowers (水

    Pashmak and Flowers Codeforces Round #261 (Div. 2) B. Pashmak and Flowers time limit per test 1 seco ...

  6. 线段树或树状数组---Flowers

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=4325 Description As is known to all, the blooming tim ...

  7. sgu 104 Little shop of flowers 解题报告及测试数据

    104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB 问题: 你想要将你的 ...

  8. 【CodeForces 621C】Wet Shark and Flowers

    题 There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such tha ...

  9. cf340 C. Watering Flowers

    C. Watering Flowers time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. 启动Sql server的服务CMD命令

    启动:net start mssqlserver 停止:net stop mssqlserver

  2. 事务(Transaction)

    1.演示转账的功能:(1)创建一张表示学生表表 CREATE TABLE student( id INT PRIMARY KEY AUTO_INCREMENT,name VARCHAR(50), ac ...

  3. HDU 6143 Killer Names(容斥原理)

    http://acm.hdu.edu.cn/showproblem.php?pid=6143 题意: 用m个字母去取名字,名字分为前后两部分,各由n个字符组成,前后两部分不能出现相同字符,问合法的组成 ...

  4. UVa 1151 买还是建

    https://vjudge.net/problem/UVA-1151 题意: 平面上有n个点,你的任务是让所有n个点连通.为此,你可以新建一些边,费用等于两个端点的距离平方和.另外还有q个套餐可以购 ...

  5. Ubuntu禁用触摸板

    参考链接: http://www.linuxidc.com/Linux/2012-08/68831.htm http://blog.sina.com.cn/s/blog_a3052b4a0100z4u ...

  6. Cocos2d-x学习笔记(六)Label字体控制

    BMFont使用链接--->>  http://blog.csdn.net/qiurisuixiang/article/details/8984288 这里要注意.fnt文件可通过BMFo ...

  7. Goroutines和Channels(二)

    网络编程是并发大显身手的一个领域,由于服务器是最典型的需要同时处理很多连接的程序,这些连接一般来自于彼此独立的客户端. 本小节,我们会讲解go语言的net包,这个包提供编写一个网络客户端或者服务器程序 ...

  8. Spring boot 遇到了连接mysql的错误

    问题1: Establishing SSL connection without server's identity verification is not recommended. Accordin ...

  9. jsp / get 中文乱码问题

    POST 方式下的解决方式还算简单,因为POST 方式下提交的数据都是以二进制的方式附加在http请求的body部分发送,只需要在后台指定编码格式就足矣解决. GET 方式下会将参数直接附加到url ...

  10. android--------热修复介绍

    热修复技术在近年来飞速发展,尤其是在InstantRun方案推出之后,各种热修复技术竞相涌现.国内大部分成熟的主流APP都拥有自己的热修复技术,像手淘.支付宝.QQ.饿了么.美团等等. 代码热修复是最 ...