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最少 ...
随机推荐
- valgrind 内存调试工具
一.valgrind 是运行在linux系统下的内存调试工具,支持很多对象:memcheck.addrcheck.cachegrind.Massif.helgrind.Callgrind等.使用val ...
- 023.Zabbix自定义(邮箱)脚本告警-02
待补充 有需要,请留言!
- 大数据技术之_16_Scala学习_02_变量
第二章 变量2.1 变量是程序的基本组成单位2.2 Scala 变量的介绍2.2.1 概念2.2.2 Scala 变量使用的基本步骤2.3 Scala 变量的基本使用2.4 Scala 变量使用说明2 ...
- 迈出第一步,Hexo博客搭建
很早之前看到别人的博客就总想着自己之后也要搭一个,最近突然来了干劲,就开始搭起了博客.不过搭博客还真是一个累活,失败了不下十次,用了好几天的时间,感觉自己在浪费时间,但是看到现在博客终于能用了,非常开 ...
- MyBatis Plus + Activiti 整合报错:org.springframework.beans.factory.UnsatisfiedDependencyException
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ind ...
- UOJ.386.[UNR #3]鸽子固定器(贪心 链表)
题目链接 \(Description\) 选最多\(m\)个物品,使得它们的\((\sum vi)^{dv}-(s_{max}-s_{min})^{du}\)最大. \(Solution\) 先把物品 ...
- 【BZOJ-2142】礼物 拓展Lucas定理
2142: 礼物 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 1313 Solved: 541[Submit][Status][Discuss] ...
- ios网络请求
1.AFNetworking object 2.Alamofire swift
- Linux学习笔记02—磁盘分区
下面介绍四种最常见的分区方式: (1) 最简单的分区方案. SWAP分区:即交换分区,建议大小是物理内存的1-2倍. /分区:建议大小在6GB以上. 使用以上的分区方案,所有的数据都在/分区上, ...
- xcode 拷贝新的ios image 进去以后 出现 the divices is locked
苹果公司时不时的给你更新下ios系统.对于开发者来说.更新xcode是灾难性的. 一直在用xcode7.3.1,可是最新不小心把手机升级到 ios 10.1.1,这下好了,真机调试不行了.提示没有镜像 ...