标签:using 复杂度 src scanf ios amp .com display hid
题目大意:
T(n) = n^k,S(n) = T(1) + T(2) + ...... T(n)。给出n和k,求S(n)。
总时间复杂度O(T*k)
代码:
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<cmath> 5 using namespace std; 6 #define M 1000000007 7 #define K 2010 8 #define ll long long 9 int T,i; 10 ll k,m,inv[K],n,j,c[K][K],b[K],Ans; 11 int main() 12 { 13 for(inv[1]=1,i=2;i<K;i++)inv[i]=(M-M/i)*inv[M%i]%M; 14 for(i=1;i<K;i++){ 15 c[i][0]=c[i][i]=1; 16 for(j=1;j<i;j++) 17 c[i][j]=(c[i-1][j]+c[i-1][j-1])%M; 18 } 19 for(b[0]=1,i=1;i<K-1;i++){ 20 for(j=0;j<i;j++)b[i]=(b[i]-b[j]*c[i+1][j])%M; 21 b[i]=(b[i]*inv[i+1])%M; 22 } 23 scanf("%d",&T); 24 while(T--){ 25 scanf("%I64d%d",&n,&k); 26 Ans=0;n%=M; 27 for(i=1,j=n+1;i<=k+1;i++,j=(j*(n+1))%M)Ans=(Ans+(c[k+1][i]*b[k-i+1]%M)*j%M)%M; 28 Ans=(Ans*inv[k+1])%M; 29 printf("%I64d\n",(Ans+M)%M); 30 } 31 return 0; 32 }
标签:using 复杂度 src scanf ios amp .com display hid
原文地址:http://www.cnblogs.com/gjghfd/p/6537017.html