zoukankan      html  css  js  c++  java
  • HDU 5793

    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 )   //等比数列求和公式
             
        接下来求快速幂和逆元即可.

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

     1 #include <iostream>
     2 #include <cstdio>
     3 using namespace std;
     4 #define LL long long
     5 const LL MOD = 1000000007;
     6 LL PowMod(LL a, LL p, LL MOD)
     7 {
     8     int res = 1;
     9     while(p)
    10     {
    11         if(p&1) res = (res * a) %MOD;
    12         p >>= 1;
    13         a = (a * a) % MOD;
    14     }
    15     return res;
    16 }
    17 int t;
    18 LL n,m;
    19 int main()
    20 {
    21     scanf("%d",&t);
    22     while(t--)
    23     {
    24         scanf("%lld%lld", &n, &m);
    25         LL ans = PowMod(m, n+1, MOD);
    26         --ans;
    27         LL inv = PowMod(m-1, MOD-2, MOD);
    28         ans = (ans * inv) % MOD;
    29         printf("%lld
    ",ans);
    30     }
    31 } 
    我自倾杯,君且随意
  • 相关阅读:
    GzipOutputStream及GzipInputStream的用法
    java的ZipOutputStream压缩文件的两个问题(乱码和每次zip后文件md5变化)
    HttpClient对URL编码的处理方式解惑!
    使用tmpfs缓存文件提高性能
    eclipse attach source code support folder zip & jar format
    HTTP头部详解及使用Java套接字处理HTTP请求
    curl使用总结
    cURL: win64sslsspi from Mirrors 64bit win7 version
    httpclient解析gzip网页
    使用Gzip加速网页的传输
  • 原文地址:https://www.cnblogs.com/nicetomeetu/p/5741774.html
Copyright © 2011-2022 走看看