HDU 5793 - A Boring Question
题意:

  计算 ( ∑(0≤K1,K2...Km≤n )∏(1≤j<m) C[Kj, Kj+1]  ) % 1000000007=? (C[Kj, Kj+1] 为组合数)
    
分析:

  利用二项式展开: (a + b) ^ n =  ∑(r = 0, n) (C[n, r] * a^(n-r) * b^r )
    
    化简:
           ∑(0≤K1,K2...Km≤n )∏(1≤j<m) C[Kj, Kj+1]
    
         = ∑( Km = 0, n ) ∑( Km-1 = 0, Km ) ∑( Km-2 = 0, Km-1 )...∑( K1 = 0, K2 ) ( C[Km, Km-1] * C[Km-1, Km-2] *...*C[K2, K1]  )
           
         = ∑( Km = 0, n ) ∑( Km-1 = 0, Km )C[Km, Km-1]  ∑( Km-2 = 0, Km-1 )C[Km-1, Km-2] ... ∑( K2 = 0, K3 )C[K3, K2]  ∑( K1 = 0, K2)C[K2, K1]   //后面的积可分别提到和式前面
                                                                                                                                    
         = ∑( Km = 0, n ) ∑( Km-1 = 0, Km )C[Km, Km-1]  ∑( Km-2 = 0, Km-1 )C[Km-1, Km-2] ... ∑( K2 = 0, K3 ) ( C[K3, K2] * 2^K2 )

                                                           // ∑( K1 = 0, K2)C[K2, K1]  为(1 + 1) ^ k2 的二项式展开
                                                                                                                                    
         = ∑( Km = 0, n ) m ^ Km          //∑( K2 = 0, K3 ) ( C[K3, K2] * 2^K2 ) 为 (1 + 2) ^ k3 的二项式展开 ,接下来依次向上化简
         
         = ( m^(n+1) - 1 ) / ( m - 1 )   //等比数列求和公式
         
    接下来求快速幂和逆元即可.

  (博客园怎么连个公式编辑器都没有= =)

 #include <iostream>
#include <cstdio>
using namespace std;
#define LL long long
const LL MOD = ;
LL PowMod(LL a, LL p, LL MOD)
{
int res = ;
while(p)
{
if(p&) res = (res * a) %MOD;
p >>= ;
a = (a * a) % MOD;
}
return res;
}
int t;
LL n,m;
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%lld%lld", &n, &m);
LL ans = PowMod(m, n+, MOD);
--ans;
LL inv = PowMod(m-, MOD-, MOD);
ans = (ans * inv) % MOD;
printf("%lld\n",ans);
}
}

HDU 5793 - A Boring Question的更多相关文章

  1. HDU 5793 A Boring Question (找规律 : 快速幂+逆元)

    A Boring Question 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5793 Description Input The first l ...

  2. HDU 5793 A Boring Question (逆元+快速幂+费马小定理) ---2016杭电多校联合第六场

    A Boring Question Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  3. HDU 5793 A Boring Question (找规律 : 快速幂+乘法逆元)

    A Boring Question Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  4. hdu 5793 A Boring Question(2016第六场多校)

    A Boring Question Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  5. HDU 5793 A Boring Question 多校训练

    There are an equation. ∑0≤k1,k2,⋯km≤n∏1⩽j<m(kj+1kj)%1000000007=?∑0≤k1,k2,⋯km≤n∏1⩽j<m(kj+1kj)%1 ...

  6. HDU 5793 A Boring Question ——(找规律,快速幂 + 求逆元)

    参考博客:http://www.cnblogs.com/Sunshine-tcf/p/5737627.html. 说实话,官方博客的推导公式看不懂...只能按照别人一样打表找规律了...但是打表以后其 ...

  7. 数学--数论--Hdu 5793 A Boring Question (打表+逆元)

    There are an equation. ∑0≤k1,k2,⋯km≤n∏1⩽j<m(kj+1kj)%1000000007=? We define that (kj+1kj)=kj+1!kj! ...

  8. 多校6 1001 HDU5793 A Boring Question (推公式 等比数列求和)

    题解:http://bestcoder.hdu.edu.cn/blog/ 多校6 HDU5793 A Boring Question // #pragma comment(linker, " ...

  9. hdu_5793_A Boring Question(打表找规律)

    题目链接:hdu_5793_A Boring Question 题意: 自己看吧,说不清楚了. 题解: 打表找规律 #include<cstdio> typedef long long l ...

随机推荐

  1. 关于DCLP实现的单例模式的一些想法

    关于DCLP实现的单例模式的一些想法 我之前写过单例的文章( http://www.cnblogs.com/mkdym/p/4908644.html ),但是现在又有了一些想法,不想再在原来那篇文章上 ...

  2. TCP/UDP网络编程的基础知识与基本示例(windows和Linux)

    一.TCP编程的一般步骤 服务器端: 1.创建一个socket,用函数socket() 2.绑定IP地址.端口等信息到socket上,用函数bind() 3.开启监听,用函数listen() 4.接收 ...

  3. 用PS画一个齿轮

    以前只会画圆画方,这没技术含量.今天学了一个稍难一点的,画一个齿轮.图形有圆也有方.以下描述如何画出来的. 一.打开PS准备一画布,画一矩形并且填充颜色. 二.编辑->自由变换(CTRL+T), ...

  4. Linux服务器配置WEB应用日志文件到指定目录

    在Linux服务器上配置WEB应用程序日志到指定文件   服务器环境是 RedHat Linux, 其上运行的是 Apache + Tomcat,容器中运行的是我们公司的壹个小型电子商务网站,原来项目 ...

  5. LeetCode_Longest Common Prefix

    Write a function to find the longest common prefix string amongst an array of strings. class Solutio ...

  6. jprofiler安装和配置

    转:http://www.cnblogs.com/adolfmc/archive/2013/06/09/3129358.html 注意:安装前先用rpm -q jprofiler查询linux上是否已 ...

  7. cf471B MUH and Important Things

    B. MUH and Important Things time limit per test 1 second memory limit per test 256 megabytes input s ...

  8. Randomized QuickSelect

    In this blog, we give a solution for Quick Select. Here, we have an improvement. The idea is to rand ...

  9. Rotate Array 解答

    Question Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, t ...

  10. ZOJ3574(归并排序求逆数对)

    Under Attack II Time Limit: 5 Seconds      Memory Limit: 65536 KB Because of the sucessfully calcula ...