HDU 4869 Turn the pokers(思维+逆元)
考试的时候没有做出来。。。
想到了答案一定是一段连续的区间,一直在纠结BFS判断最后的可行1数。
原来直接模拟一遍就可以算出来最后的端点。。。
剩下的就是组合数取模了,用逆元就行了。。。
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi 3.1415926535
# define eps 1e-
# define MOD
# define INF
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<,l,mid
# define rch p<<|,mid+,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
int Scan() {
int res=, flag=;
char ch;
if((ch=getchar())=='-') flag=;
else if(ch>=''&&ch<='') res=ch-'';
while((ch=getchar())>=''&&ch<='') res=res*+(ch-'');
return flag?-res:res;
}
void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
const int N=;
//Code begin... LL f[N];
LL pow_mod(LL a, LL n, LL mod){
LL ret=, tmp=a%mod;
while (n) {
if (n&) ret=ret*tmp%MOD;
tmp=tmp*tmp%MOD;
n>>=;
}
return ret;
}
LL inv(LL a, LL mod){return pow_mod(a,mod-,mod);}
void init(){
f[]=;
FO(i,,N) f[i]=(f[i-]*i)%MOD;
}
int main ()
{
int n, m, x, l, r, tmpl, tmpr;
LL ans;
init();
while (~scanf("%d%d",&n,&m)) {
l=r=;
ans=;
FOR(i,,n) {
scanf("%d",&x);
if (l>=x) tmpl=l-x;
else if(r>=x) tmpl=((l%)==(x%))?:;
else tmpl=x-r;
if (r+x<=m) tmpr=r+x;
else if(l+x<=m) tmpr=(((l+x)%)==(m%)?m:m-);
else tmpr=*m-l-x;
l=tmpl; r=tmpr;
}
for (int i=l; i<=r; i+=) ans=(ans+(f[m]*inv(f[i]*f[m-i]%MOD,MOD))%MOD)%MOD;
printf("%lld\n",ans);
}
return ;
}
HDU 4869 Turn the pokers(思维+逆元)的更多相关文章
- HDU 4869 Turn the pokers(推理)
HDU 4869 Turn the pokers 题目链接 题意:给定n个翻转扑克方式,每次方式相应能够选择当中xi张进行翻转.一共同拥有m张牌.问最后翻转之后的情况数 思路:对于每一些翻转,假设能确 ...
- HDU 4869 Turn the pokers(思维+组合公式+高速幂)
pid=4869" target="_blank">Turn the pokers 大意:给出n次操作,给出m个扑克.然后给出n个操作的个数a[i],每一个a[i] ...
- 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多校联合第一场 I)
Turn the pokers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 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 (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最少 ...
随机推荐
- Scala快速入门到精通 视频教程 百度云网盘下载地址
Scala快速入门到精通 视频教程 百度云网盘下载地址 Scala快速入门到精通 下载地址链接:https://pan.baidu.com/s/1bqGIKyF 密码:ojwd
- 优步UBER司机全国各地奖励政策汇总 (2月29日-3月6日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- 北京Uber优步司机奖励政策(3月14日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- day 4 集合
1.集合 In [1]: a = (11,22,33,11,22,33) In [2]: a Out[2]: (11, 22, 33, 11, 22, 33) #元组 In [3]: b = [11, ...
- 能用程序解决的问题绝不BB之租房篇章...
项目缘起于高德API+Python解决租房问题, 修修补补之后上线了58公寓高德搜房(全国版)http://woyaozufang.live:8080. 经过了多次代码优化.内容改版.新增房源等... ...
- dubbo之监控中心(monitor)
一.monitor是dubbo框架中的一个监控中心.这个只是针对于消费者和提供者进行一个数据记录,不参与业务和使用.当然当monitor挂掉之后,也不会影响服务的正常运行. 二.在阿里的dubbo中也 ...
- 转 Cobar使用文档(可用作MySQL大型集群解决方案)
转自:http://blog.csdn.net/shagoo/article/details/8191346 最近好不容易抽空研究了下Cobar,感觉这个产品确实很不错(在文档方面比Amoeba强多了 ...
- Qt-QML-C++交互实现文件IO系统-后继-具体文件IO的实现
在上一篇文章中,我大致将这个QML中的文件IO类搭出了大致的框架,那么,今天抽时间写了一点文件的读写,这里我使用的文件流来读写文件. 文件结构如图 在QML中调用这个类了,就见简单的读取了一个JSON ...
- python操作字符串内容并重新输出
今天在做一个函数的作业,题目如下: 编写一个函数实现大写转小写,小写变大写,并且转换为镜像字符串,并且将字符串变为镜像字符串. 例如:’A’变为’Z’,’b’变为’y 示范字符串: ”sdSdsfdA ...
- C 基本运算
一 算术运算 C语言一共有34种运算符 包括了常见的加减乘除运算 1. 加法运算+ 除开能做加法运算 还能表示正号: +5, +90 2. 减法运算- 除开能做减法运算 还能表示符号: -10, -2 ...