• HDU 4869 Turn the pokers


    Turn the pokers

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

    Problem Description

    During summer vacation,Alice stay at home for a long time, with nothing to do. She went out and bought m pokers, tending to play poker. But she hated the traditional gameplay. She wants to change. She puts these pokers face down, she decided to flip poker n 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?

    Input

    The input consists of multiple test cases. 
    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).

    Output

    Output the required answer modulo 1000000009 for each test case, one per line.

    Sample Input

    3 43 2 33 33 2 3

    Sample Output

    83 

    Hint

    For the second example:0 express face down,1 express face upInitial state 000The first result:000->111->001->110The second result:000->111->100->011The third result:000->111->010->101So, there are three kinds of results(110,011,101)



    区间维护非常绕人!

    !。。!

    前面把它想简单了,无限跪!!

    还有组合数高速幂求模。曾经都没记这东西!!!

    按题解在赛后总算把它A了!


    AC代码例如以下:


    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #define mod 1000000009
    #define ll long long
    #define M 100005
    using namespace std;
    
    ll n,m;
    ll a[M],c[M];
    
    ll pow_mod(ll a,ll b)
    {
        ll s=1;
        while(b)
        {
            if(b&1)s=s*a%mod;
            a=a*a%mod;
            b=b>>1;
        }
        return s;
    }
    
    int main()
    {
        ll i,j;
        ll ans,minn,maxx;
        while(~scanf("%lld%lld",&n,&m))
        {
    
            ans=0;
            ll l=0,r=0;
            for(i=0;i<n;i++)
            {
                scanf("%lld",&a[i]);
                if(a[i]==m||a[i]==0)
                    continue;
                if(r+a[i]<=m)//右区间的改变
                    maxx=r+a[i];
                else if(l+a[i]<=m)
                    maxx=((m+l+a[i])&1)?m-1:m;
                else maxx=m+m-l-a[i];
                if(l-a[i]>=0)//左区间的改变
                    minn=l-a[i];
                else if(r-a[i]>=0)
                    minn=((l+a[i])&1)?

    1:0; else minn=a[i]-r; l=minn;r=maxx; } //cout<<l<<"~~~~~~~~"<<r<<endl; c[0]=1; for(ll k=1;k<=m;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; } for(i=l;i<=r;i+=2)//区间肯定是同奇偶的 ans=(ans+c[i])%mod; printf("%I64d ",ans); } return 0; }



  • 相关阅读:
    城市生态规划关键技术方法之三:城市生态系统服务功能理论与方法
    AE中用矢量数据剪裁栅格
    城市生态规划的基本原理与程序
    城市生态规划关键技术方法之一:生态系统健康理论与方法
    城市生态规划的基本概念、内容与方法
    终于找到使用Sql Server Management Studio导致蓝屏的罪魁祸首了
    保证相同类型的MDI子窗体只会被打开一次的方法
    甩掉数据字典,让Sql Server数据库也来一个自描述
    新鲜试用IE8 beta2
    让我目瞪口呆的program.exe
  • 原文地址:https://www.cnblogs.com/mqxnongmin/p/10933288.html
Copyright © 2020-2023  润新知