hdu 4869 Turn the pokers 策略(组合数)
题意:输入操作次数n和扑克牌数m,一開始扑克牌全都背面朝上。
如今输入n个数xi,表示选择xi张牌翻转,问最后的牌的情况有多少种可能?
题解:
我们将一開始的牌觉得是m个0。而翻转就是将0变成1或者1变成0。
最后的答案就是ans=∑C(m,k)。C(m。k)为组合数,k为全部能取到的1的可能个数。具体的解释,先了解最后1的个数的奇偶性,跟全部翻牌数的和的奇偶同样(每次翻牌,要么0->1。要么1->0,都是在改变1的个数奇偶)。之后我们须要找到最少有i个1,以及最大有j个1;i的情况就是有1就翻1,j的情况就是有0就翻0,而中间的情况时。取偶数步数,一半翻0。一半翻1,保持不变。所以能够确定i,i+2,i+4,...,j-2,j都能被翻到。最后ans=∑C(m,k)(i<=k<=j&&k%2==i%2)。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
using namespace std; #define LL __int64
const int maxn=1e5+10;
const int mod=1e9+9;
LL c[maxn];
LL pow_mod(LL a,int b)
{
LL s=1;
while(b)
{
if(b&1)s=s*a%mod;
a=a*a%mod;
b=b>>1;
}
return s;
}
int main()
{
int n,m;
//freopen("C:\\Documents and Settings\\Administrator\\桌面\\in.txt","r",stdin);
//freopen("C:\\Documents and Settings\\Administrator\\桌面\\out.txt","w",stdout);
//printf("%I64d\n",pow_mod(2,10));
while(scanf("%d%d",&n,&m)!=EOF)
{
int i,j,k,x,p,q;
i=j=0;
for(k=0;k<n;k++)
{
scanf("%d",&x);
//求最小1的个数i
if(i>=x)p=i-x;
else if(j>=x)p=((i&1)==(x&1)?0:1);
else p=x-j;
//求最大1的个数j
if(j+x<=m)q=j+x;
else if(i+x<=m)q=(((i+x)&1)==(m&1)?m:m-1);
else q=2*m-(i+x);
i=p;j=q;
//printf("**%d %d\n",i,j);
} LL ans=0;
c[0]=1;
if(i==0)ans+=c[0];
for(k=1;k<=j;k++)
{
if(m-k<k)c[k]=c[m-k];
else c[k]=c[k-1]*(m-k+1)%mod*pow_mod(k,mod-2)%mod;
if(k>=i&&(k&1)==(i&1))ans+=c[k];
}
printf("%I64d\n",ans%mod);
}
return 0;
}
hdu 4869 Turn the pokers 策略(组合数)的更多相关文章
- HDU 4869 Turn the pokers(推理)
HDU 4869 Turn the pokers 题目链接 题意:给定n个翻转扑克方式,每次方式相应能够选择当中xi张进行翻转.一共同拥有m张牌.问最后翻转之后的情况数 思路:对于每一些翻转,假设能确 ...
- 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 (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(组合数+费马小定理)
Problem Description During summer vacation,Alice stay at home for a long time, with nothing to do. S ...
- 2014多校第一场 I 题 || HDU 4869 Turn the pokers(费马小定理+快速幂模)
题目链接 题意 : m张牌,可以翻n次,每次翻xi张牌,问最后能得到多少种形态. 思路 :0定义为反面,1定义为正面,(一开始都是反), 对于每次翻牌操作,我们定义两个边界lb,rb,代表每次中1最少 ...
- HDU 4869 Turn the pokers (2014 多校联合第一场 I)
HDOJ--4869--Turn the pokers[组合数学+快速幂] 题意:有m张扑克,开始时全部正面朝下,你可以翻n次牌,每次可以翻xi张,翻拍规则就是正面朝下变背面朝下,反之亦然,问经过n次 ...
随机推荐
- Jmeter中的参数化常用的几种方式
Jmeter中的参数化常用的几种方式,这里讲一下前两个方式,最后一个在csv参数化里已详细讲解. 1.用户参数 2.函数助手 3.CSV Data Set Config 一.用户参数 位置:添加-前 ...
- Vim中文编码问题
1.影响中文编码的设置项 encoding(enc):encoding是Vim的内部使用编码,encoding的设置会影响Vim内部的Buffer.消息文字等.在 Unix环境下,encoding的默 ...
- MySQL 中去重 distinct 用法
在使用MySQL时,有时需要查询出某个字段不重复的记录,这时可以使用mysql提供的distinct这个关键字来过滤重复的记录,但是实际中我们往往用distinct来返回不重复字段的条数(count( ...
- Caffe结构
caffe可以分为3层结构:blob,layer,net 在layer中,input data用bottom表示,output data用top表示.每一个layer定义了三种操作,setup(Lay ...
- Linux C下变量和常量的存储的本质
源代码 #cat main.c #include <stdio.h> int i = 100; int main(void) { func(); return 0; } #cat func ...
- [C#] 对List进行分组排序后输出
Student 类: public class Student { public int ID { get; set; } public string Name { get; set; } publi ...
- 实现基于pam认证的vsftpd
1 需求 使用指定虚拟用户Allen与Barry登录ftp,认证的源是mysql服务器: Allen可以上传文件,Barry不可以上传文件: 2 环境 [root@centos7 ~]# cat /e ...
- SQL-如何使用 MongoDB和PyMongo。
先决条件 在开始之前,请确保已经安装了 PyMongo 发行版. 在 Python shell 中,下面的代码应该在不引发异常的情况下运行: >>> import pymongo 假 ...
- 集训第四周(高效算法设计)E题 (区间覆盖问题)
UVA10382 :http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=21419 只能说这道题和D题是一模一样的,不过要进行转化, ...
- 安装 asp.net core 出错
I received the same error message on a fresh Windows 10 install, with a fresh Visual Studio 2015 ins ...