CF932E Team Work

题目链接:洛谷

题目大意:求$$\sum_{i=1}^nC_{n}^ii^k$$

数据范围:$1\leq n\leq 10^9,1\leq k\leq 5000$

这道题就是完全的模板了

$$ans=\sum_{i=1}^nC_n^i\sum_{d=0}^kd!S(k,d)C_i^d$$

$$=\sum_{d=0}^kd!S(k,d)\sum_{i=1}^nC_n^iC_i^d$$

$$=\sum_{d=0}^kd!S(k,d)C_n^d\sum_{i=d}^nC_{n-d}^{i-d}$$

$$=\sum_{d=0}^kd!S(k,d)C_n^d2^{n-d}$$

至于那个等式

$$C_n^iC_i^d=C_n^dC_{n-d}^{i-d}$$

只要根据组合数的定义拆一下就可以了。

 1 #include<cstdio>
 2 #define Rint register int
 3 using namespace std;
 4 typedef long long LL;
 5 const int N = 5003, mod = 1e9 + 7;
 6 int n, k, S[N][N], ans;
 7 inline int kasumi(int a, int b){
 8     int res = 1;
 9     while(b){
10         if(b & 1) res = (LL) res * a % mod;
11         a = (LL) a * a % mod;
12         b >>= 1;
13     }
14     return res;
15 }
16 int main(){
17     scanf("%d%d", &n, &k);
18     S[0][0] = 1;
19     for(Rint i = 1;i <= k;i ++)
20         for(Rint j = 1;j <= i;j ++)
21             S[i][j] = ((LL) S[i - 1][j] * j + S[i - 1][j - 1]) % mod;
22     int fac = 1, cho = 1;
23     for(Rint i = 1;i <= k && i <= n;i ++){
24         cho = (LL) cho * (n - i + 1) % mod * kasumi(i, mod - 2) % mod;
25         fac = (LL) fac * i % mod;
26         ans = (ans + (LL) fac * cho % mod * kasumi(2, n - i) % mod * S[k][i] % mod) % mod;
27     }
28     printf("%d", ans);
29 }
View Code

 

posted @ 2019-03-18 18:24  mizu164  阅读(239)  评论(0编辑  收藏  举报