hdu5793 A Boring Question(推公式or迷之找规律)

来源:互联网 发布:矩阵和伴随矩阵的秩 编辑:程序博客网 时间:2024/05/09 23:50

思路:比赛时候是迷之手玩了很多个样例然后大胆猜测了一发公式...

正解:

A Boring Question

\sum_{0\leq k_{1},k_{2},\cdots k_{m}\leq n}\prod_{1\leq j< m}\binom{k_{j+1}}{k_{j}}0k1,k2,kmn1j<m(kjkj+1) =\sum_{0\leq k_{1}\leq k_{2}\leq\cdots \leq k_{m}\leq n}\prod_{1\leq j< m}\binom{k_{j+1}}{k_{j}}=0k1k2kmn1j<m(kjkj+1) =\sum_{k_{m}=0}^{n}\sum_{k_{m-1}=0}^{k_{m}}\cdots \sum_{k_{1}=0}^{k_{2}}\prod_{1\leq j< m}\binom{k_{j+1}}{k_{j}}=km=0nkm1=0kmk1=0k21j<m(kjkj+1) =\sum_{k_{m}=0}^{n}\left { \binom{k_{m}}{k_{m-1}} \sum_{k_{m-1}=0}^{k_{m}} \left { \binom{k_{m-1}}{k_{m-2}} \cdots \sum_{k_{1}=0}^{k_{2}}\binom{k_{2}}{k_{1}} \right } \right }=km=0n{(km1km)km1=0km{(km2km1)k1=0k2(k1k2)}} =\sum_{k_{m}=0}^{n}\left { \binom{k_{m}}{k_{m-1}} \sum_{k_{m-1}=0}^{k_{m}} \left { \binom{k_{m-1}}{k_{m-2}} \cdots \sum_{k_{1}=0}^{k_{2}}\binom{k_{2}}{k_{1}} \right } \right }=km=0n{(km1km)km1=0km{(km2km1)k1=0k2(k1k2)}} =\sum_{k_{m}=0}^{n}\left { \binom{k_{m}}{k_{m-1}} \sum_{k_{m-1}=0}^{k_{m}} \left { \binom{k_{m-1}}{k_{m-2}} \cdots \sum_{k_{2}=0}^{k_{3}}\binom{k_{3}}{k_{2}}2^{k_{2}} \right } \right }=km=0n{(km1km)km1=0km{(km2km1)k2=0k3(k2k3)2k2}} =\sum_{k_{m}=0}^{n}m^{k_{m}}=km=0nmkm =\frac{m^{n+1} - 1}{m - 1}=m1mn+11

#include<bits/stdc++.h>using namespace std;const int mod = 1e9+7;#define LL long longtemplate<class T1,class T2>T1 quick_mod(T1 t,T2 n){T1 ans=1;while(n){if(n&1) ans=ans*t%mod;t=t*t%mod;n>>=1;}return ans;}LL Inv(LL x){return quick_mod(x, mod-2);}int main(){    int T;scanf("%d",&T);while(T--){LL n,m;scanf("%lld%lld",&n,&m);if(n==0){printf("1\n");continue;}LL inv = Inv(m-1);LL ans = ((quick_mod(m,n+1)-1)*inv)%mod;printf("%lld\n",ans);}}

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
21 22 3
 

Sample Output
313
 

Author
UESTC
 

Source
2016 Multi-University Training Contest 6


0 0