# 洛谷P4593 [TJOI2018]教科书般的亵渎 【数学】

## 题解

orz dalao

$(n + 1)^{k + 1} - n^{k + 1} = \sum\limits_{i = 1}^{k + 1} {k + 1\choose i}n^{k + 1 - i}$

\begin{aligned} (n + 1)^{k + 1} - n^{k + 1} &= \sum\limits_{i = 1}^{k + 1} {k + 1\choose i}n^{k + 1 - i} \n^{k + 1} - (n - 1)^{k + 1} &= \sum\limits_{i = 1}^{k + 1} {k + 1\choose i}(n - 1)^{k + 1 - i} \......... \2^{k + 1} - 1^{k + 1} &= \sum\limits_{i = 1}^{k + 1} {k + 1\choose i}1^{k + 1 - i} \\end{aligned}

$(n + 1)^{k + 1} - 1 = \sum\limits_{i= 1}^{k + 1} {k + 1 \choose i} S(n,k + 1 - i)$

$S(n,k) = \frac{(n + 1)^{k + 1} - 1 - \sum\limits_{i = 2}^{k + 1}{k + 1 \choose i} S(n,k + 1 - i)}{k + 1}$

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define mp(a,b) make_pair<int,int>(a,b)
#define cls(s) memset(s,0,sizeof(s))
#define cp pair<int,int>
#define LL long long int
using namespace std;
const int maxn = 105,maxm = 100005,INF = 1000000000,P = 1000000007;
LL out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == ‘-‘) flag = -1; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
return out * flag;
}
int n,m,K,fac[maxn],fv[maxn],inv[maxn];
LL a[maxn];
void init(){
fac[0] = fac[1] = fv[0] = fv[1] = inv[0] = inv[1] = 1;
for (int i = 2; i < maxn; i++){
fac[i] = 1ll * fac[i - 1] * i % P;
inv[i] = 1ll * (P - P / i) * inv[P % i] % P;
fv[i] = 1ll * fv[i - 1] * inv[i] % P;
}
}
LL C(LL n,LL m){
return 1ll * fac[n] * fv[m] % P * fv[n - m] % P;
}
LL qpow(LL a,LL b){
LL ans = 1; a %= P;
for (; b; b >>= 1,a = a * a % P)
if (b & 1) ans = ans * a % P;
return ans;
}
LL f[maxn];
LL S(LL n,LL k){
if (!n) return 0;
f[0] = n;
for (int i = 1; i <= k; i++){
LL tmp = 0;
for (int j = 2; j <= i + 1; j++)
tmp = (tmp + C(i + 1,j) * f[i + 1 - j]) % P;
f[i] = (((qpow(n + 1,i + 1) - 1) % P - tmp) % P + P) % P * inv[i + 1] % P;
}
return f[k];
}
LL b[maxn];
int main(){
init();
while (T--){
REP(i,m) a[i] = read(); a[K] = n + 1;
sort(a + 1,a + 1 + K);
LL ans = 0;
for (int i = 0; i <= m; i++){
for (int j = i; j <= m; j++){
ans = ((ans + (S(a[j + 1] - 1,K) - S(a[j],K)) % P) % P + P) % P;
}
LL len = a[i + 1] - a[i];
for (int j = i + 1; j <= K; j++) a[j] -= len;
}
printf("%lld\n",ans);
}
return 0;
}

(0)
(0)

0条