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 ...
随机推荐
- JAVA I/O(二)文件NIO
一.Unix五种I/O模型 读取和写入文件I/O操作都是调用操作系统提高的接口,对磁盘I/O来说,一般是将数据从磁盘拷贝到内核空间,然后从内核空间拷贝到用户空间.为了减小I/O时间,一般内核空间存在高 ...
- Python3基础 list 使用for循环 删除列表中的重复项
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- JavaScript 获取地址栏参数
1. function a() { console.log(this); } a.call(null); window 如果第一个参数传入的对象调用者是null或者undefined的话,call方法 ...
- Linq 对List的一些操作
代码: public class Person { public int ID { get; set; } public string Name { get; set; } public int Ag ...
- 【Apache】的运营之道
1.“一个修修补补”的服务? 大家可能听说过 Apache 是一个双关语 “a patchy Web server”,意思为一个修修补补的 web 服务,即通过一系列的补丁做的服务.但是这并不是 Ap ...
- HDU 2546 饭卡(0-1背包)
http://acm.hdu.edu.cn/showproblem.php?pid=2546 题意: 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金 ...
- python 集合从头部删除元素
num_set = , , , , ]) num_set.pop() print(num_set) num_set.pop() print(num_set)
- shell printf
printf 可以格式化字符串,还可以制定字符串的宽度.左右对齐方式等.默认 printf 不会像 echo 自动添加换行符,我们可以手动添加 \n. 例子: $ echo "Hello, ...
- pyqt 调用颜色选择器
# -*- coding: utf- -*- from PyQt5.QtWidgets import QApplication, QPushButton, QColorDialog , QWidget ...
- windows cmd 命令和 linux 命令
windows cmd 命令和 linux 命令 常用的内部命令有md.cd.rd.dir.path.copy.type.edit.ren.del.cls.ver.date.time.prompt.常 ...