【题目链接】

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的更多相关文章

  1. 【81.82%】【codeforces 740B】Alyona and flowers

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  3. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  4. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  5. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  6. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  7. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  8. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  9. 【Codeforces 670C】 Cinema

    [题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...

随机推荐

  1. 去除DialogFragment的背景阴影,背景色,标题栏

    style中: <resources xmlns:android="http://schemas.android.com/apk/res/android"> <s ...

  2. SQL Server2008优化之SET STATISTICS开关

    一.准备工作 缓存对于某个查询的性能影响十分之大,所以优化之前要清空缓存. 清除Buffer Pool时面的所有缓存 DBCC DROPCLEANBUFFERS清除Buffer Pool里的所有缓存的 ...

  3. 各个数据库中,查询前n条记录的方法

    SQL查询前10条的方法为: 1.select top X *  from table_name --查询前X条记录,可以改成需要的数字,比如前10条. 2.select top X *  from  ...

  4. session 存入redis 或 memcache 的方法

      Session简介 session,中文经常翻译为会话,其本来的含义是 指有始有终的一系列动作/消息,比如打电话时从拿起电话拨号到挂断电话这中间的一系列过程可以称之为一个session.有时候我们 ...

  5. python处理中文编码

    python2 读取excle中的数据时,对于汉字的读取报错: 代码:data[num][4]={"content": "测试"} data=data[num] ...

  6. js DOM 节点树 设置 style 样式属性

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  7. javaee字符文件的复制

    package Zy; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWrit ...

  8. ptyhon获取app设备号、包名、activity

    直接上代码: import time import os import re import sys #------------------------------------------------- ...

  9. 【例题4-2 uva489】Hangman Judge

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 水题. 中间就赢了算赢.(重复说,算错 [代码] #include <bits/stdc++.h> using name ...

  10. 1013MySQL监控利器-Innotop

    转自 http://www.cnblogs.com/ivictor/p/5101506.html 安装过程中 可以使用 YUM INSTALL INNOTOP进行直接安装 Innotop是一款十分强大 ...