【Codeforces 258E】 Devu and Flowers
【题目链接】
http://codeforces.com/contest/451/problem/E
【算法】
容斥原理
【代码】
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int P = 1e9 + ; int i,j,n,s,ans,MASK;
ll m,t;
ll a[],f[];
int inv[]; inline int power(int a,int n)
{
int res = ,b = a;
while (n)
{
if (n & ) res = 1ll * res * b % P;
b = 1ll * b * b % P;
n >>= ;
}
return res;
}
inline int C(ll x,int y)
{
int i,res = ;
if (y < || x < y || x < ) return ;
if (x == || y == ) return ;
x %= P;
for (i = x; i >= x - y + ; i--) res = 1ll * res * i % P;
for (i = ; i <= y; i++) res = 1ll * res * inv[i] % P;
return res;
} int main()
{ scanf("%d%I64d",&n,&m);
for (i = ; i <= n; i++) scanf("%I64d",&a[i]);
for (i = ; i <= ; i++) inv[i] = power(i,P-);
MASK = << n;
ans = ;
for (i = ; i < MASK; i++)
{
if (i == ) ans = (ans + C(n+m-,n-)) % P;
else
{
s = ;
t = n + m;
for (j = ; j < n; j++)
{
if (i & ( << j))
{
s++;
t -= a[j+];
}
}
t -= (s + );
if (s & ) ans = (ans - C(t,n-) + P) % P;
else ans = (ans + C(t,n-)) % P;
}
}
printf("%d\n",ans); return ; }
【Codeforces 258E】 Devu and Flowers的更多相关文章
- 【81.82%】【codeforces 740B】Alyona and flowers
		time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ... 
- 【codeforces 415D】Mashmokh and ACM(普通dp)
		[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ... 
- 【codeforces 707E】Garlands
		[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ... 
- 【codeforces 707C】Pythagorean Triples
		[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ... 
- 【codeforces 709D】Recover the String
		[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ... 
- 【codeforces 709B】Checkpoints
		[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ... 
- 【codeforces 709C】Letters Cyclic Shift
		[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ... 
- 【Codeforces 429D】 Tricky Function
		[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ... 
- 【Codeforces 670C】 Cinema
		[题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ... 
随机推荐
- nodejs脚手架express-generator
			1.安装生成器 npm install express-generator -g 2. 创建名称为APP的应用: express my-project 3.安装依赖包 cd my-project np ... 
- VHDL之concurrent之generate
			GENERATE It is another concurrent statement (along with operators and WHEN). It is equivalent to the ... 
- 读书笔记「Python编程:从入门到实践」_4.操作列表
			4.1 遍历整个列表 4.1.1 深入地研究循环 4.1.2 在for循环中执行更多的操作 4.1.3 在for循环结束后执行一些操作 例 magicians = ['alice', ' ... 
- 团体程序设计天梯赛-练习集-L1-038. 新世界
			L1-038. 新世界 这道超级简单的题目没有任何输入. 你只需要在第一行中输出程序员钦定名言“Hello World”,并且在第二行中输出更新版的“Hello New World”就可以了. #in ... 
- matlab学习菜单控件的基本用法
			编辑菜单项 上下文菜单,即弹出菜单 然后添加一个坐标系 添加回调函数 %余弦曲线x=0:0.01:2*pi;y=cos(x);axes(handles.axes1);%将坐标系的值写进h=plot(x ... 
- matlab学习下拉菜单
			用matlab添加listbox控件 修改string和value值,value为几就对应第几行字符串 添加button按钮,将string值改为“选择x轴参数”,字体大小为10 再添加一个按钮,将s ... 
- JAVA中实现根据文件路径下载文件
			import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.FileInputStream; ... 
- Django 路由视图FBV/CBV
			路由层 url路由层结构 from django.conf.urls import url from django.contrib import admin from app01 import vi ... 
- 504 Gateway Timeout 异常
			生产销售系统出现 504 Gateway Timeout 异常,其实就是服务器响应太慢导致nginx带来超时,先不说服务端慢的优化问题:只是单纯的解决504.到网上发现了一篇文章fix it Add ... 
- [luogu1627  CQOI2009] 中位数 (乱搞)
			传送门 Solution 好水的题(ーー;) Code //By Menteur_Hxy #include <map> #include <queue> #include &l ... 
