HDOJ 4869 Turn the pokers
最后的结果中正面向上的奇偶性是一定的,计算出正面向上的范围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
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?
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).
3 4
3 2 3
3 3
3 2 3
8
3HintFor 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)
#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的更多相关文章
- HDU 4869 Turn the pokers(推理)
HDU 4869 Turn the pokers 题目链接 题意:给定n个翻转扑克方式,每次方式相应能够选择当中xi张进行翻转.一共同拥有m张牌.问最后翻转之后的情况数 思路:对于每一些翻转,假设能确 ...
- hdu 4869 Turn the pokers (2014多校联合第一场 I)
Turn the pokers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4869 Turn the pokers(思维+组合公式+高速幂)
pid=4869" target="_blank">Turn the pokers 大意:给出n次操作,给出m个扑克.然后给出n个操作的个数a[i],每一个a[i] ...
- 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 ...
- hdu 4869 Turn the pokers (思维)
Turn the pokers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4869 Turn the pokers (2014多校联合训练第一场1009) 解题报告(维护区间 + 组合数)
Turn the pokers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 4869 Turn the pokers(组合数+费马小定理)
Problem Description During summer vacation,Alice stay at home for a long time, with nothing to do. S ...
- HDU 4869 Turn the pokers (2014 多校联合第一场 I)
HDOJ--4869--Turn the pokers[组合数学+快速幂] 题意:有m张扑克,开始时全部正面朝下,你可以翻n次牌,每次可以翻xi张,翻拍规则就是正面朝下变背面朝下,反之亦然,问经过n次 ...
- 2014多校第一场 I 题 || HDU 4869 Turn the pokers(费马小定理+快速幂模)
题目链接 题意 : m张牌,可以翻n次,每次翻xi张牌,问最后能得到多少种形态. 思路 :0定义为反面,1定义为正面,(一开始都是反), 对于每次翻牌操作,我们定义两个边界lb,rb,代表每次中1最少 ...
随机推荐
- mongo连接数满问题处理
记一次mongo服务端无法建立更多连接造成的客户端无法访问mongo集群的故障分析及解决 一. 问题: 程序无法连接mongo集群 现象: 2017-09-05T01:29:08.765+0000 I ...
- 001.NTP简介
一 NTP简介 ntp服务器顾名思义就是时间同步服务器(Network Time Protocol),时间同步对于计划备份.入侵检测记录.分布式任务调度或者事务订单管理来说都是非常有必要的日常任务. ...
- 决策树ID3算法--python实现
参考: 统计学习方法>第五章决策树] http://pan.baidu.com/s/1hrTscza 决策树的python实现 有完整程序 决策树(ID3.C4.5.CART ...
- Android-多进程初识
Android-多进程初识 学习自 <Android开发艺术探索> https://baike.baidu.com/item/%E8%BF%9B%E7%A8%8B/382503?fr=al ...
- Linux驱动之USB(个人)
USB概述 <USB简介> a:背景 USB是Universal Serial Bus的缩写,是一种全新的,双向同步传输的,支持热插拔的 ...
- [HDU2874]Connections between cities
思路:LCA裸题.本来是帮pechpo调错,结果自己写了半天… 设$dis_x$是点$x$到根结点距离,不难想到两点$u$.$v$之间最短距离等于$dis_u+dis_v-dis_{LCA(u,v)} ...
- 如何利用Reveal神器查看各大APP UI搭建层级
作者 乔同X2016.08.22 19:45 写了3195字,被42人关注,获得了73个喜欢 如何利用Reveal神器查看各大APP UI搭建层级 字数413 阅读110 评论0 喜欢5 title: ...
- MikroTik RouterOS 5.x使用HunterTik 2.3.1进行破解
一.加载光驱: 二.一路回车: 三.说明: 1.可以不安装Debian内核,但如果在无缝升级到6.6的版本,此项就一定要选择. 2.6版本的破解必须小于等于1G的空间,不然无法破解成功,亲测有效,如果 ...
- SWD and JTAG selection mechanism
SWD and JTAG selection mechanism SWJ-DP enables either an SWD or JTAG protocol to be used on the deb ...
- STM32的CRC32 测试代码
// STM32 CRC32 Test App - sourcer32@gmail.com #include <windows.h> #include <stdio.h> DW ...