# bzoj 3157 国王奇遇记 - 数学

……没有任何算法的推式子……

${F}_{k}=\sum _{i=1}^{n}{i}^{k}×{m}^{i}$

${F}_{k}=\sum _{i=1}^{n}\left(i-1+1{\right)}^{k}×{m}^{i-1+1}$

${F}_{k}=m+\sum _{i=1}^{n-1}\left(i+1{\right)}^{k}×{m}^{i+1}$

${F}_{k}=m-\left(n+1{\right)}^{k}×{m}^{n+1}+\sum _{i=1}^{n}\left(i+1{\right)}^{k}×{m}^{i+1}$

${F}_{k}=m-\left(n+1{\right)}^{k}×{m}^{n+1}+\sum _{i=1}^{n}\sum _{j=0}^{k}\left(\genfrac{}{}{0}{}{k}{j}\right){i}^{j}×{m}^{i+1}$

${F}_{k}=m-\left(n+1{\right)}^{k}×{m}^{n+1}+m\sum _{j=0}^{k}\left(\genfrac{}{}{0}{}{k}{j}\right)\sum _{i=1}^{n}{i}^{j}×{m}^{i}$

${F}_{k}=m-\left(n+1{\right)}^{k}×{m}^{n+1}+m\sum _{j=0}^{k}\left(\genfrac{}{}{0}{}{k}{j}\right){F}_{j}$

$\left(m-1\right){F}_{k}=\left(n+1{\right)}^{k}×{m}^{n+1}-m-m\sum _{j=0}^{k-1}\left(\genfrac{}{}{0}{}{k}{j}\right){F}_{j}$

${F}_{k}=\frac{\left(n+1{\right)}^{k}×{m}^{n+1}-m-m\sum _{j=0}^{k-1}\left(\genfrac{}{}{0}{}{k}{j}\right){F}_{j}}{m-1}$

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define N 210
#define lint long long
#define mod 1000000007
#define inv(x) fast_pow(x,mod-2)
using namespace std;
int s[N],c[N][N],mi[N];
inline int fast_pow(int x,int k,int ans=1)
{
for(;k;k>>=1,x=(lint)x*x%mod)
if(k&1) ans=(lint)ans*x%mod;
return ans;
}
int main()
{
int n,m,t;scanf("%d%d",&n,&m),mi[0]=fast_pow(m,n+1),t=inv(m-1);
if(m==1) return !printf("%lld\n",(lint)n*(n+1)%mod*inv(2)%mod);
for(int i=1;i<=m;i++) mi[i]=(lint)mi[i-1]*(n+1)%mod;
s[0]=(lint)t*(mi[0]-m+mod)%mod,c[0][0]=1;
for(int i=1;i<=m;i++)
for(int j=c[i][0]=1;j<=i;j++)
c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
for(int i=1;i<=m;i++)
{
for(int j=(s[i]=1)-1;j<i;j++)
(s[i]+=(lint)c[i][j]*s[j]%mod)%=mod;
s[i]=(lint)t*(mi[i]-(lint)m*s[i]%mod+mod)%mod;
}
return !printf("%d\n",s[m]);
}