[CF932E] Team Work
题目链接
Codeforces:https://codeforces.com/problemset/problem/932/E
Solution
直接把幂转成斯特林数然后暴力就好了。
\[\begin{align}ans=&\sum_{i=1}^{n}\binom{n}{i}i^x\\=&\sum_{i=1}^{n}\binom{n}{i}\sum_{j=1}^{k}s_2(k,j)\binom{i}{j}j!\\=&\sum_{j=1}^{k}s_2(k,j)\frac{n!}{(n-k)!}2^{n-j}\end{align}
\]
复杂度\(O(k^2)\)。
#include<bits/stdc++.h>
using namespace std;
void read(int &x) {
x=0;int f=1;char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}
void print(int x) {
if(x<0) putchar('-'),x=-x;
if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}
#define lf double
#define ll long long
#define pii pair<int,int >
#define vec vector<int >
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)
const int maxn = 5e3+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;
int n,k,s[maxn][maxn],ans;
int qpow(int a,int x) {
int res=1;
for(;x;x>>=1,a=1ll*a*a%mod) if(x&1) res=1ll*res*a%mod;
return res;
}
int main() {
read(n),read(k);s[0][0]=1;
for(int i=1;i<=k;i++)
for(int j=1;j<=i;j++)
s[i][j]=(1ll*j*s[i-1][j]+s[i-1][j-1])%mod;
for(int i=1;i<=k&&i<=n;i++) {
int res=1;
for(int j=n;j>n-i;j--) res=1ll*res*j%mod;
res=1ll*res*qpow(2,n-i)%mod;
res=1ll*res*s[k][i]%mod;
ans=(ans+res)%mod;
}
write(ans);
return 0;
}