最后的结果中正面向上的奇偶性是一定的,计算出正面向上的范围low,up

结果即为 C(m。low)+ C(m。low+2) +.... + C(m,up) ,用逆元取模

Turn the pokers

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 828    Accepted Submission(s): 302

Problem Description
During summer vacation,Alice stay at home for a long time, with nothing to do. She went out and bought m pokers, tending to play poker. But she hated the traditional gameplay. She wants to change. She puts these pokers face down, she decided to flip poker n
times, and each time she can flip Xi pokers. She wanted to know how many the results does she get. Can you help her solve this problem?
 
Input
The input consists of multiple test cases. 

Each test case begins with a line containing two non-negative integers n and m(0<n,m<=100000). 

The next line contains n integers Xi(0<=Xi<=m).
 
Output
Output the required answer modulo 1000000009 for each test case, one per line.
 
Sample Input
3 4
3 2 3
3 3
3 2 3
 
Sample Output
8
3
Hint
For the second example:
0 express face down,1 express face up
Initial state 000
The first result:000->111->001->110
The second result:000->111->100->011
The third result:000->111->010->101
So, there are three kinds of results(110,011,101)
 
Author
FZU
 
Source
 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; typedef long long int LL; const int maxn=110000;
const LL mod=1000000009LL; LL a[maxn],n,m; void ex_gcd(LL a,LL b,LL &d,LL &x,LL &y)
{
if(!b)
{
d=a; x=1; y=0;
}
else
{
ex_gcd(b,a%b,d,y,x);
y-=a/b*x;
}
} LL lower,upper; void cal(LL lower,LL upper)
{
LL cur=1LL,t=0,ret=0;
while(t<=upper)
{
if(t>=lower&&t<=upper)
if((t-lower)%2==0)
ret=(ret+cur)%mod;
t++;
cur=(cur*(m-t+1))%mod;
LL d,x,y;
ex_gcd(t,mod,d,x,y);
x=(x+mod)%mod;
cur=(cur*x)%mod;
}
cout<<ret<<endl;
} int main()
{
while(cin>>n>>m)
{
lower=upper=0LL;
for(int i=0;i<n;i++)
cin>>a[i];
lower=upper=a[0];
for(int i=1;i<n;i++)
{
LL last_low=lower,last_up=upper; ///get low bound
if(a[i]<=last_low)
lower-=a[i];
else if(a[i]<=last_up)
lower=0+((a[i]+last_up)%2==1);
else
lower=a[i]-last_up; ///get upper bound
if(a[i]+last_up<=m)
upper=a[i]+last_up;
else if(a[i]+last_low<=m)
upper=m-((a[i]+last_low)%2==1);
else
upper=m-(a[i]+last_low-m);
}
cal(lower,upper);
}
return 0;
}

HDOJ 4869 Turn the pokers的更多相关文章

  1. HDU 4869 Turn the pokers(推理)

    HDU 4869 Turn the pokers 题目链接 题意:给定n个翻转扑克方式,每次方式相应能够选择当中xi张进行翻转.一共同拥有m张牌.问最后翻转之后的情况数 思路:对于每一些翻转,假设能确 ...

  2. hdu 4869 Turn the pokers (2014多校联合第一场 I)

    Turn the pokers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. HDU 4869 Turn the pokers(思维+组合公式+高速幂)

    pid=4869" target="_blank">Turn the pokers 大意:给出n次操作,给出m个扑克.然后给出n个操作的个数a[i],每一个a[i] ...

  4. HDU 4869 Turn the pokers (2014 Multi-University Training Contest 1)

    Turn the pokers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  5. hdu 4869 Turn the pokers (思维)

    Turn the pokers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. HDU 4869 Turn the pokers (2014多校联合训练第一场1009) 解题报告(维护区间 + 组合数)

    Turn the pokers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. hdu 4869 Turn the pokers(组合数+费马小定理)

    Problem Description During summer vacation,Alice stay at home for a long time, with nothing to do. S ...

  8. HDU 4869 Turn the pokers (2014 多校联合第一场 I)

    HDOJ--4869--Turn the pokers[组合数学+快速幂] 题意:有m张扑克,开始时全部正面朝下,你可以翻n次牌,每次可以翻xi张,翻拍规则就是正面朝下变背面朝下,反之亦然,问经过n次 ...

  9. 2014多校第一场 I 题 || HDU 4869 Turn the pokers(费马小定理+快速幂模)

    题目链接 题意 : m张牌,可以翻n次,每次翻xi张牌,问最后能得到多少种形态. 思路 :0定义为反面,1定义为正面,(一开始都是反), 对于每次翻牌操作,我们定义两个边界lb,rb,代表每次中1最少 ...

随机推荐

  1. 009.Zabbix幻灯片展示

    一 Slide shows简介 Slide shows在多个Screens之间以幻灯片的方式来展示,使一个屏幕可以显示多个页面. 二 Slide shows配置 2.1 创建多个Screen Slid ...

  2. 004.Zabbix3.x-Server服务端安装

    一 环境基础 1.1 部署基础环境 部署Zabbix需要LAMP或LANP环境,数据库可以为MySQL或者MariaDB.硬件及存储条件按需配置. 1.2 常见依赖列表 Web前端需要支持的软件环境如 ...

  3. 深入理解Git - 一切皆commit

    在对 git 有了基本理解和知道常规操作之后,如何对 git 的使用有进一步的理解? 一切皆 commit 或许是个不错的理解思路. 本文将从『一切皆 commit 』的角度,通过 git 中常见的名 ...

  4. Python3 k-邻近算法(KNN)

    # -*- coding: utf-8 -*- """ Created on Fri Dec 29 13:13:44 2017 @author: markli " ...

  5. 隧道接口工具airtun-ng

    隧道接口工具airtun-ng   airtun-ng是aircrack-ng套件提供的一个工具.该工具可以为无线网卡建立隧道接口.通过该接口,渗透测试人员可以建立wIDS,分析指定的AP的数据.借助 ...

  6. 基于.htaccess的Web Shell工具htshells

    基于.htaccess的Web Shell工具htshells   .htaccess文件是Apache服务器的配置文件.它负责相关目录下的网页配置.一旦用户获得修改该文件的权限,就可以基于该文件构建 ...

  7. CSS 设计理念

    今天整理CSS2.1的规范,发现这个,分享给大家. CSS2.1 作为 CSS2 和 CSS1 的后序版本,基于一下一组设计理念: 向前和向后兼容.CSS2.1 的用户代理能够理解 CSS1 的样式表 ...

  8. Code Forces 698A Vacations

    题目描述 Vasya has nn days of vacations! So he decided to improve his IT skills and do sport. Vasya know ...

  9. canvas知识点积累

    fillRect(x,y,width,height) 填充一个矩形区域,绘制已填色的矩形,默认填充颜色为黑色.x:矩形左上横坐标,y:矩形左上纵坐标,width:矩形宽度,height:矩形高度. s ...

  10. Android SDKVersion 参数列表

    http://developer.android.com/guide/topics/manifest/uses-sdk-element.html Platform Version API Level ...