# CF961G Partitions(第二类斯特林数)

CF961G

## 做法

\begin{aligned}\\ Sum&=\sum\limits_{s=1}^n s\cdot C_{n-1}^{s-1}\begin{Bmatrix}n-s\\k-1\end{Bmatrix}\\ &=\sum\limits_{s=1}^n s\cdot C_{n-1}^{s-1}\sum\limits_{i=0}^{k-1}\frac{(-1)^i}{i!}\frac{(k-i-1)^{n-2}}{(k-i-1)!}\\\ &=\sum\limits_{i=0}^{k-1}\frac{(-1)^i}{i!(k-i-1)!}\sum\limits_{s=1}^n s\cdot C_{n-1}^{s-1}(k-i-1)^{n-s}\\ &=\sum\limits_{i=0}^{k-1}\frac{(-1)^i}{i!(k-i-1)!}(\sum\limits_{s=1}^nC_{n-1}^{s-1}(k-i-1)^{n-s}+\sum\limits_{s=1}^n (s-1)C_{n-1}^{s-1}(k-i-1)^{n-s})\\ &=\sum\limits_{i=0}^{k-1}\frac{(-1)^i}{i!(k-i-1)!}(\sum\limits_{s=1}^nC_{n-1}^{s-1}(k-i-1)^{n-s}+(n-1)\sum\limits_{s=1}^n C_{n-2}^{s-2}(k-i-1)^{n-s})\\ &=\sum\limits_{i=0}^{k-1}\frac{(-1)^i}{i!(k-i-1)!}((k-i)^{n-1}+(n-1)(k-i)^{n-2})\\ &=\sum\limits_{i=0}^{k-1}\frac{(-1)^i}{i!(k-i-1)!}(k-i)^{n-2}(k-i+n-1)\\ \end{aligned}

$Ans=\sum\limits_{i=1}^nw_i(\begin{Bmatrix}n\\k\end{Bmatrix}+(n-1)\begin{Bmatrix}n-1\\k\end{Bmatrix})$

## Code

#include<cstdio>
typedef int LL;
const LL mod=1e9+7,maxn=2e5+9;
LL x(0),f(1); char c=getchar();
while(c<'0' || c>'9'){
if(c=='-') f=-1; c=getchar();
}
while(c>='0' && c<='9'){
x=(x<<3)+(x<<1)+c-'0'; c=getchar();
}
return x*f;
}
inline LL Pow(LL base,LL b){
LL ret(1);
while(b){
if(b&1) ret=1ll*ret*base%mod; base=1ll*base*base%mod; b>>=1;
}return ret;
}
LL fav[maxn],fac[maxn];
inline LL Get(LL n,LL m){
LL ret(0);
for(LL i=0;i<=m;++i)
ret=1ll*(ret+1ll*(i&1?mod-1:1)*fav[i]%mod*Pow(m-i,n)%mod*fav[m-i]%mod)%mod;
return ret;
}
LL n,sum,k;
LL w[maxn];
int main(){