考试的时候没有做出来。。。

想到了答案一定是一段连续的区间,一直在纠结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(思维+逆元)的更多相关文章

  1. HDU 4869 Turn the pokers(推理)

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

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

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

  3. hdu 4869 Turn the pokers (思维)

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

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

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

  5. 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 ...

  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. React Router 4.0 实现路由守卫

    在使用 Vue 或者 Angular 的时候,框架提供了路由守卫功能,用来在进入某个路有前进行一些校验工作,如果校验失败,就跳转到 404 或者登陆页面,比如 Vue 中的 beforeEnter 函 ...

  2. nodejs module/require

    1. wrap up a module using module.exports, name the file to a.js var fun1=function(){ var stylus = re ...

  3. hive读书笔记

    笔记来源<Hive编程指南> 一.hive命令行界面: ‘一次使用’命令:执行一个或多个(分号分隔)查询后hive CLI立即退出: hive -e "select * from ...

  4. Bing wallpaper api

    list: http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=zh-cn idx:-1为明天,1为 ...

  5. Bootstrap基础篇—常见的CSS类

    一.标题 标签 大小 h1 36px h2 30px h3 24px h4 18px h5 14px h6 12px 二.常见的内联样式 标签 用途 del 删除的文本 s 无用的文本 ins 插入的 ...

  6. hdu2066一个人的旅行(floyd优化)

    一个人的旅行 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  7. Python列表操作大全(非常全)

    Python列表操作大全(非常全!!!) 对于python列表的理解可以和C语言里面的数组进行比较性的记忆与对照,它们比较相似,对于python里面列表的定义可以直接用方括号里加所包含对象的方法,并且 ...

  8. 适配iPhoneX、iPhoneXs、iPhoneXs Max、iPhoneXr 屏幕尺寸及安全区域

    此篇文章是对上一篇文章(http://www.ifiero.com/index.php/archives/611)的进一步补充,主要说明如何适配Apple的最新三款手机iPhoneXs.iPhoneX ...

  9. Java开发工程师(Web方向) - 01.Java Web开发入门 - 第5章.Git

    第5章--Git 版本控制简介 VCS (version control system) 版本控制系统:记录若干文件的修订记录的系统,帮助查阅/回到某个历史版本 LVCS本地 CVCS集中式(Cent ...

  10. go通过第三方库 mahonia gbk 转utf8

    go get github.com/axgle/mahonia dec := mahonia.NewDecoder("GBK")ret:=dec.ConvertString(res ...