• hdu 5187 zhx's contest


    zhx's contest

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 3119    Accepted Submission(s): 1006

    Problem Description
    As one of the most powerful brushes, zhx is required to give his juniors n problems.
    zhx thinks the ith problem's difficulty is i. He wants to arrange these problems in a beautiful way.
    zhx defines a sequence {ai} beautiful if there is an i that matches two rules below:
    1: a1..ai are monotone decreasing or monotone increasing.
    2: ai..an are monotone decreasing or monotone increasing.
    He wants you to tell him that how many permutations of problems are there if the sequence of the problems' difficulty is beautiful.
    zhx knows that the answer may be very huge, and you only need to tell him the answer module p.
     
    Input
    Multiply test cases(less than 1000). Seek EOF as the end of the file.
    For each case, there are two integers n and p separated by a space in a line. (1n,p1018)
     
    Output
    For each test case, output a single line indicating the answer.
     
    Sample Input
    2 233 3 5
     
    Sample Output
    2 1
    Hint
    In the first case, both sequence {1, 2} and {2, 1} are legal. In the second case, sequence {1, 2, 3}, {1, 3, 2}, {2, 1, 3}, {2, 3, 1}, {3, 1, 2}, {3, 2, 1} are legal, so the answer is 6 mod 5 = 1
     
    Source
     
    Recommend
    hujie   |   We have carefully selected several similar problems for you:  6205 6204 6203 6202 6201 
    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    long long n,p,num,ans;
    long long fastmul(long long a,long long b,long long p){ 
        long long bns=0;  
        a=a%p;
        b=b%p;
        while(b>0){
            if(b&1) bns=(bns+a)%p;
            a=(a+a)%p;
            b>>=1;
        }
        return bns;
    }
    long long fastpow2(long long a,long long x,long long p){
        long long s=1%p;
        for(;x;x>>=1){
            if(x&1)
                s=(long long)fastmul(s,a,p)%p;
            a=(long long)fastmul(a,a,p)%p;
        }
        return s;
    }
    int main(){
    //    freopen("permutation.in","r",stdin);
    //    freopen("permutation.out","w",stdout);
        while(scanf("%I64d%I64d",&n,&p)!=EOF){
            if(n==1){
                cout<<"0"<<endl;
                continue;
            }
            num=fastpow2(2,n-2,p);
            ans=fastmul(4,num-1,p);
            ans=(ans+2)%p;
            printf("%I64d
    ",ans);
        }
    }
     
    细雨斜风作晓寒。淡烟疏柳媚晴滩。入淮清洛渐漫漫。 雪沫乳花浮午盏,蓼茸蒿笋试春盘。人间有味是清欢。
  • 相关阅读:
    bzoj2809 [Apio2012]dispatching
    bzoj2743[HEOI2012]采花
    bzoj3626[LNOI2014]LCA
    bzoj2038 [2009国家集训队]小Z的袜子(hose)——莫队
    bzoj2442[Usaco2011 Open]修剪草坪——单调队列优化
    bzoj1588[HNOI2002]营业额统计——双向链表
    洛谷1527(bzoj2738)矩阵乘法——二维树状数组+整体二分
    bzoj1503[NOI2004]郁闷的出纳员——Splay
    洛谷P2014——选课
    洛谷P1352——动规
  • 原文地址:https://www.cnblogs.com/cangT-Tlan/p/7514802.html
Copyright © 2020-2023  润新知