【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 ...
随机推荐
- 【技术累积】【点】【sql】【17】了解索引
先上结论 数据库数据以平衡树进行聚合索引--主键的作用: 数据每行都存在叶子节点: 单独字段的索引,单独存在,且将该字段值取出: 单独字段的索引,查到对应的主键id,再通过聚合索引查到数据: 多字段索 ...
- FormCollection获取请求数据
public ActionResult Add(FormCollection fm) //通过FormCollection 对象获取表单数据 { string message = "&quo ...
- BZOJ 3012: [Usaco2012 Dec]First! 字典树 + tarjan
Code: #include<bits/stdc++.h> #define maxn 1000003 using namespace std; char str[maxn],strtot[ ...
- 15.4 Task 异步匿名函数
Func<int, Task<int>> func = async x => { Console.WriteLine("starting x={0}" ...
- 一个vue模拟键盘的组件
如图所示下载地址
- svn版本库更新后自动同步到www
注意:www目录一定要用SVN服务器 checkout出Repositories的代码 步骤: (1)新建www根目录 mkdir -p /data/www/lehuo (2)在www根目录下检出(c ...
- 爬虫系列(十三) 用selenium爬取京东商品
这篇文章,我们将通过 selenium 模拟用户使用浏览器的行为,爬取京东商品信息,还是先放上最终的效果图: 1.网页分析 (1)初步分析 原本博主打算写一个能够爬取所有商品信息的爬虫,可是在分析过程 ...
- AtCoder ABC 070D - Transit Tree Path
传送门:http://abc070.contest.atcoder.jp/tasks/abc070_d 本题是一个图论问题——树(Tree). 有一棵结点数目为n的无向树.第i条边连接结点ai与bi, ...
- .net 单元测试
都说测试驱动开发,但是想写好单元测试其实不容易,不是因为测试用例难以构造,而是因为很多时候方法非常复杂 其中部分测试想要完成就十分费力,其中让人崩溃的地方主要如下: 实例私有函数 实例静态私有函数 十 ...
- 如鹏网JAVA培训笔记2(晓伟整理)
输入输出: 我们使用System.out.println(“abc”);作用:向控制台输入东西. Scaner sc=new Scanner(System.in)://从输入流中去读取 int age ...