zoukankan      html  css  js  c++  java
  • hdu-5793 A Boring Question(二项式定理)

    题目链接:

    A Boring Question

    Time Limit: 2000/1000 MS (Java/Others)   

     Memory Limit: 65536/65536 K (Java/Others)


    Problem Description
    There are an equation.
    0k1,k2,kmn1j<m(kj+1kj)%1000000007=?
    We define that (kj+1kj)=kj+1!kj!(kj+1kj)! . And (kj+1kj)=0 while kj+1<kj.
    You have to get the answer for each n and m that given to you.
    For example,if n=1,m=3,
    When k1=0,k2=0,k3=0,(k2k1)(k3k2)=1;
    Whenk1=0,k2=1,k3=0,(k2k1)(k3k2)=0;
    Whenk1=1,k2=0,k3=0,(k2k1)(k3k2)=0;
    Whenk1=1,k2=1,k3=0,(k2k1)(k3k2)=0;
    Whenk1=0,k2=0,k3=1,(k2k1)(k3k2)=1;
    Whenk1=0,k2=1,k3=1,(k2k1)(k3k2)=1;
    Whenk1=1,k2=0,k3=1,(k2k1)(k3k2)=0;
    Whenk1=1,k2=1,k3=1,(k2k1)(k3k2)=1.
    So the answer is 4.
     
    Input
    The first line of the input contains the only integer T,(1T10000)
    Then T lines follow,the i-th line contains two integers n,m,(0n109,2m109)
     
    Output
     
    For each n and m,output the answer in a single line.
     
    Sample Input
     
    2
    1 2
    2 3
     
    Sample Output
     
    3
    13
     
    题意:
     
    就是求这个式子的值是多少;
     
    思路:
     
    ∑(km,km-1)(km-1,km-2)...(k2,k1)=∑(km,km-1)...(k3,k2)(∑(k2,k1){0<=k1<=k2})=∑(km,km-1)...∑(k3,k2)*2k2 
    ∑(k3,k2)*2k2 =(1+2)k3;二项式定理,以后也是这样,最后得到的结果为(mn+1-1)/(m-1);
     
    AC代码:
     
    /************************************************
    ┆  ┏┓   ┏┓ ┆   
    ┆┏┛┻━━━┛┻┓ ┆
    ┆┃       ┃ ┆
    ┆┃   ━   ┃ ┆
    ┆┃ ┳┛ ┗┳ ┃ ┆
    ┆┃       ┃ ┆ 
    ┆┃   ┻   ┃ ┆
    ┆┗━┓    ┏━┛ ┆
    ┆  ┃    ┃  ┆      
    ┆  ┃    ┗━━━┓ ┆
    ┆  ┃  AC代马   ┣┓┆
    ┆  ┃           ┏┛┆
    ┆  ┗┓┓┏━┳┓┏┛ ┆
    ┆   ┃┫┫ ┃┫┫ ┆
    ┆   ┗┻┛ ┗┻┛ ┆      
    ************************************************ */ 
     
     
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <bits/stdc++.h>
    #include <stack>
     
    using namespace std;
     
    #define For(i,j,n) for(int i=j;i<=n;i++)
    #define mst(ss,b) memset(ss,b,sizeof(ss));
     
    typedef  long long LL;
     
    template<class T> void read(T&num) {
        char CH; bool F=false;
        for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
        for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
        F && (num=-num);
    }
    int stk[70], tp;
    template<class T> inline void print(T p) {
        if(!p) { puts("0"); return; }
        while(p) stk[++ tp] = p%10, p/=10;
        while(tp) putchar(stk[tp--] + '0');
        putchar('
    ');
    }
     
    const LL mod=1e9+7;
    const double PI=acos(-1.0);
    const int inf=1e9;
    const int N=1e6+10;
    const int maxn=2e3+14;
    const double eps=1e-12;
    
    LL pow_mod(LL x,LL y)
    {
        LL s=1,base=x;
        while(y)
        {
            if(y&1)s=s*base%mod;
            base=base*base%mod;
            y>>=1;
        }
        return s;
    }
    
    int main()
    {      
            int t;
            read(t);
            while(t--)
            {
                LL n,m;
                read(n);read(m);
                cout<<(pow_mod(m,n+1)-1+mod)%mod*pow_mod(m-1,mod-2)%mod<<"
    ";
            }
            return 0;
    }
    

      

  • 相关阅读:
    数据库备份与还原
    启明星产品与微软Active Directory活动目录集成说明
    启明星请假系统里,计算工作日的实现
    启明星会议室预定系统Outlook版开始支持Exchange2013与Office365版
    Jquery Mobile实例--利用优酷JSON接口读取视频数据
    高性能且线程安全的两种格式化日期方式
    将数列唯一值化后再求中值的效率比较 第一方案胜出,加索引后在近两百万数据中查出中值耗时0.176秒
    Oracle WITH 语句 语法
    新三种求数列中值SQL之效率再比拼
    rank,dense_rank和row_number函数区别
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5737926.html
Copyright © 2011-2022 走看看