51nod1269Devu and Flowers
题解:
如果没有限制每一种花有多少,那么就是简单的排列组合问题。
那么我们强制让一些花一定都要选。
暴力搜索,然后组合数(逆元)
采用容斥原理来计算最后的答案
代码:
#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的更多相关文章
- CF451E Devu and Flowers (隔板法 容斥原理 Lucas定理 求逆元)
Codeforces Round #258 (Div. 2) Devu and Flowers E. Devu and Flowers time limit per test 4 seconds me ...
- poj 3262 Protecting the Flowers
http://poj.org/problem?id=3262 Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Tota ...
- 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 ...
- poj1157LITTLE SHOP OF FLOWERS
Description You want to arrange the window of your flower shop in a most pleasant way. You have F bu ...
- CF459B Pashmak and Flowers (水
Pashmak and Flowers Codeforces Round #261 (Div. 2) B. Pashmak and Flowers time limit per test 1 seco ...
- 线段树或树状数组---Flowers
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=4325 Description As is known to all, the blooming tim ...
- sgu 104 Little shop of flowers 解题报告及测试数据
104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB 问题: 你想要将你的 ...
- 【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 ...
- cf340 C. Watering Flowers
C. Watering Flowers time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- VC++ 实现修改文件创建、访问、修改时间属性(转载)
转载:http://sunnysab.blog.163.com/blog/static/18037500920134221295425/ struct _FILETIME { //结构体定义 DWOR ...
- keepalived主从及双主配置
高可用有2中方式. 1.Nginx+keepalived 主从配置 这种方案,使用一个vip地址,前端使用2台机器,一台做主,一台做备,但同时只有一台机器工作,另一台备份机器在主机器不出现故障的时候, ...
- excel的C#操作教程
C# Excel Tutorial http://csharp.net-informations.com/excel/csharp-excel-tutorial.htm How to transfer ...
- HBase底层存储原理——我靠,和cassandra本质上没有区别啊!都是kv 列存储,只是一个是p2p另一个是集中式而已!
理解HBase(一个开源的Google的BigTable实际应用)最大的困难是HBase的数据结构概念究竟是什么?首先HBase不同于一般的关系数据库,它是一个适合于非结构化数据存储的数据库.另一个不 ...
- 深度优先搜索之小z的房子与验证码识别
题目:小z的房子 高级语言程序设计实践题目:2.4 小z 的房子 ★实验任务 小z 通过自己的努力,终于发家致富.现在小明有一个大小为N*M 的 院子,雨后积起了水.四联通的积水被认为是连接在一起的. ...
- gcc 编译出现 internal compiler error: Killed
系统没有交换分区, 编译过程中内存耗尽, 导致了编译中断 …解决方式也很简单, 就是增加一个交换分区: 创建分区文件, 大小 2G dd if=/dev/zero of=/swapfile ...
- Asp.net Ajax(ashx)
主要实现 ajax分页功能 效果图 后台方法代码展示 /// <summary> /// WebAjax处理类 /// </summary> public class WebA ...
- Flutter学习笔记(三)-- 事件交互和State管理
先来看看准备界面: image.png 目标是修改图中红色实线框中的喜欢和不喜欢的五角星的修改,以及数字的修改. 在修改之前,有必要先了解一些相关的信息. 知识点 前面简单的提到过,有些Widget是 ...
- Java的八种基本类型:(按字节来分)
Java的八种基本类型:(按字节来分) boolean 布尔型 1个字节 8bit(8位) byte 字节类型 1个字节 char 字符类型 2个字节 short ...
- Java知识集锦
Java知识集锦 一.Java程序基础 1.1 开发和运行环境 1.2 Java语言概述 二.Java语法基础 2.1 基础类型和语法 2.2 对象和类型 2.3 包和访问控制 三.数据类型及类型转换 ...