zoukankan      html  css  js  c++  java
  • 。。。

    #include<cstdio>
    using namespace std;
    #ifdef WINVER
    #define lld "%I64d"
    #else
    #define lld "%lld"
    #endif
    typedef long long LL;
    const LL maxn(1000005), mod(1e9 + 7);
    LL Jc[maxn];
    void calJc() {
        Jc[0]=Jc[1]=1;
        for(LL i=2;i<maxn;i++) Jc[i]=Jc[i - 1]*i%mod;
    }
    LL pow(LL a,LL n,LL p) {
        LL ans = 1;
        while(n) {
            if(n&1)ans=ans*a%p;
            a=a*a%p,n>>=1;
        }
        return ans;
    }
    LL inv(LL a, LL b) {return pow(a,b-2,b);}
    LL C(LL a, LL b) {return Jc[a]*inv(Jc[b],mod)%mod*inv(Jc[a-b],mod)%mod;}
    int main() {
        calJc();
        long long p,q,n,Q;
        scanf(lld,&Q);
        while(Q--) {
            scanf(lld lld lld,&p,&q,&n);
            printf(lld "
    ",C(p+q+n+1,p+q+1));
        }
        return 0;
    }
    #include<cstdio>
    #include<vector>
    using namespace std;
    #ifdef WINVER
    #define lld "%I64d"
    #else
    #define lld "%lld"
    #endif
    typedef long long ll;
    typedef vector<ll> vec;
    typedef vector<vec> matrix;
    const ll m=1e9+7;
    inline matrix operator *(const matrix &A,const matrix&B) {
        register int sizeA=A.size(),sizeB=B.size(),sizeB0=B[0].size();
        matrix C(sizeA,vec(sizeB0));
        for(int i=0;i<sizeA;i++)
            for(int k=0;k<sizeB;k++)
                for(int j=0;j<sizeB0;j++)
                    C[i][j]=(C[i][j]+A[i][k]*B[k][j])%m;
        return C;
    }
    inline matrix pow(matrix A,ll n) {
        register int sizeA=A.size();
        matrix B(sizeA,vec(sizeA));
        for(register int i=0;i<sizeA;i++) B[i][i]=1;
        while(n) {
            if(n&1)B=B*A;
            A=A*A;
            n>>=1;
        }
        return B;
    }
    inline matrix init(ll n,ll m) {
        matrix A(n,vec(n));
        for(register int i=0;i<n;i++)
            for(register int j=0;j<n;j++)
                A[i][j]=i==j?0:1;
        return pow(A,m);
    }
    int main() {
        ll q,n,m,a,b;
        scanf(lld lld lld,&q,&n,&m);
        matrix ans=init(m,n);
        while(q--) {
            scanf(lld lld,&a,&b);
            printf(lld"
    ",ans[a-1][b-1]);
        }
        return 0;
    }
  • 相关阅读:
    Knol of Fabio Maulo
    调用非.net系统的Webservice的探索 ( 二 ) WSE
    在Sql Server 使用系统存储过程sp_rename修改表名或列名
    Who is locking the DB account?
    (python learn) 7 字典
    (python learn) 8 流程控制
    (python learn) 4 number&& string
    where is the data come from after we drop the table
    (healthy recorder) 治疗第6天
    (python learn) 6 列表
  • 原文地址:https://www.cnblogs.com/Mary-Sue/p/9270850.html
Copyright © 2011-2022 走看看