zoukankan      html  css  js  c++  java
  • 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-9
    # define MOD 1000000009
    # define INF 1000000000
    # 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<<1,l,mid
    # define rch p<<1|1,mid+1,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=0, flag=0;
        char ch;
        if((ch=getchar())=='-') flag=1;
        else if(ch>='0'&&ch<='9') res=ch-'0';
        while((ch=getchar())>='0'&&ch<='9')  res=res*10+(ch-'0');
        return flag?-res:res;
    }
    void Out(int a) {
        if(a<0) {putchar('-'); a=-a;}
        if(a>=10) Out(a/10);
        putchar(a%10+'0');
    }
    const int N=100005;
    //Code begin...
    
    LL f[N];
    LL pow_mod(LL a, LL n, LL mod){
        LL ret=1, tmp=a%mod;
        while (n) {
            if (n&1) ret=ret*tmp%MOD;
            tmp=tmp*tmp%MOD;
            n>>=1;
        }
        return ret;
    }
    LL inv(LL a, LL mod){return pow_mod(a,mod-2,mod);}
    void init(){
        f[0]=1;
        FO(i,1,N) f[i]=(f[i-1]*i)%MOD;
    }
    int main ()
    {
        int n, m, x, l, r, tmpl, tmpr;
        LL ans;
        init();
        while (~scanf("%d%d",&n,&m)) {
            l=r=0;
            ans=0;
            FOR(i,1,n) {
                scanf("%d",&x);
                if (l>=x) tmpl=l-x;
                else if(r>=x) tmpl=((l%2)==(x%2))?0:1;
                else tmpl=x-r;
                if (r+x<=m) tmpr=r+x;
                else if(l+x<=m) tmpr=(((l+x)%2)==(m%2)?m:m-1);
                else tmpr=2*m-l-x;
                l=tmpl; r=tmpr;
            }
            for (int i=l; i<=r; i+=2) ans=(ans+(f[m]*inv(f[i]*f[m-i]%MOD,MOD))%MOD)%MOD;
            printf("%lld
    ",ans);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    检测服务器是否开启重协商功能(用于CVE-2011-1473漏洞检测)
    Wireshark解密HTTPS流量的两种方法
    text2pcap: 将hex转储文本转换为Wireshark可打开的pcap文件
    Hibernate框架(五)Hibernate主键生成策略
    HIbernate框架(四)实现添加操作
    Hibernaete框架(三)搭建hibernate环境(重点)
    Hibernate框架(二)什么是orm思想(重点)
    Hibernate框架(一)Hibernate框架是什么?
    拦截器和过滤器的区别
    谈谈java中遍历Map的几种方法
  • 原文地址:https://www.cnblogs.com/lishiyao/p/6629304.html
Copyright © 2011-2022 走看看