题解:

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

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

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

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

代码:

#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. perl入门知识(3)

    引用       在很多场合下使用引用传值,能在很大程度上提高代码的运行效率.       定义一个引用在变量名前加”\”就可以了,如:       $ra=\$a;       $rb=\@b;   ...

  2. Ambari安装指南

    一.准备工作 l 基本工具 1) 安装epel,epel是一个提供高质量软件包的项目.先检查主机上是否安装: rpm -q epel-release 2) 如果没有安装,使用rpm命令安装: rpm ...

  3. 【NOI2013】树的计数

    Description 我们知道一棵有根树可以进行深度优先遍历(DFS)以及广度优先遍历(BFS)来生成这棵树的DFS序以及BFS序.两棵不同的树的DFS序有可能相同,并且它们的BFS序也有可能相同, ...

  4. Qt_QString.indesOf和mid测试

    1.indexOf #define GID_PREFIX "dr_" QString str = "dr__awedr4"; int iIdx = str.in ...

  5. [原][OSG][osgBullet][osgworks][bullet]编译osgBullet尝试物理引擎

    相关网址: 类似文章:http://blog.csdn.net/lh1162810317/article/details/17475297 osgBullet官网:http://osgbullet.v ...

  6. javascript异步编程方案汇总剖析

    code[class*="language-"] { padding: .1em; border-radius: .3em; white-space: normal; backgr ...

  7. 封装DLL并调用

    c# DLL封装并调用   1.封装自己的dll: a.打开visual studio - 文件 - 新建 - 项目- 类库 - 名称MyTestDll: b.右键Class1.cs - 修改为 Te ...

  8. English trip -- VC(情景课)1 E Writing

    Talk with a partner ['pɑːtnə] (伙伴)  与同伴说一说 Comple the words 写全单词 first second third last name area c ...

  9. LeetCode--069--x的平方根

    问题描述: 实现 int sqrt(int x) 函数. 计算并返回 x 的平方根,其中 x 是非负整数. 由于返回类型是整数,结果只保留整数的部分,小数部分将被舍去. 示例 1: 输入: 4 输出: ...

  10. 12月14日 bs-grid , destroy_all()

    bootstrap Grid : The Bs grid system has four classes: xs (phones), sm (tablets), md (desktops), and ...