题解:

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

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

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

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

代码:

#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. 记录Java中对url中的参数进行编码

    Code: import java.net.URLEncoder; import java.util.HashMap; import java.util.Iterator; import java.u ...

  2. 源码编译安装keepalived

    首先到官网下载需要的包:http://www.keepalived.org/download.html [root@localhost local]# .tar.gz [root@localhost ...

  3. Several Service Control Manager Issues (Event ID's 7000, 7009, 7011)

    https://answers.microsoft.com/en-us/windows/forum/windows_7-performance/several-service-control-mana ...

  4. 论文笔记——ThiNet: A Filter Level Pruning Method for Deep Neural Network Compreesion

    论文地址:https://arxiv.org/abs/1707.06342 主要思想 选择一个channel的子集,然后让通过样本以后得到的误差最小(最小二乘),将裁剪问题转换成了优化问题. 这篇论文 ...

  5. Java-master(github)教材整理

    helloworld class HelloWorld { public static void main(String[] args) { System.out.println("hell ...

  6. js中拼接HTML方式方法及注意事项

    博主原创:未经博主允许,不得转载 在前端应用中,经常需要在js中动态拼接HTML页面,比如应用ajax进行局部刷新的时候,就需要在js中拼接HTML页面. 主要规则是将HTML页面的标签拼接为标签字符 ...

  7. BZOJ 2467: [中山市选2010]生成树(矩阵树定理+取模高斯消元)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2467 题意: 思路:要用矩阵树定理不难,但是这里的话需要取模,所以是需要计算逆元的,但是用辗转相减会 ...

  8. UVa 11292 勇者斗恶龙

    https://vjudge.net/problem/UVA-11292 题意:有n条任意个头的恶龙,你希望雇一些其实把它杀死.一个能力值为x的骑士可以砍掉恶龙一个直径不超过x的头,且需要支付x个金币 ...

  9. yii2 高级版新建一个应用(api应用为例子)

    先在项目的根目录下复制一份 backend 为 api: cp backend/ api -r 拷贝 api 环境 cp -a environments/dev/frontend environmen ...

  10. .NET反射的优化

    写在前面 1)本篇博客并非原创,而是我针对.NET反射相关知识的总结.本篇内容来源汇总于3篇博客.在后面的介绍中会在开头给出对应的链接,方便读者自行学习.2)本篇博客主要针对表达式树代码进行详细讲解. ...