[CF 582D]Number of Binominal Coefficients
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[CF 582D]Number of Binominal Coefficients相关的知识,希望对你有一定的参考价值。
题目大意:
给定质数p,正整数α,A,求使\({\alpha ^p}|C_m^n(0 \le m \le n \le A \le {10^{1000}})(m,n \in N)\)成立的(m,n)组数.
介绍一个恶心的定理:库默尔定理,定理描述如下:
组合数\(C_m^{m + n}\)所含的p的幂次数为
\(\sum\limits_{i = 1}^\infty {\left( {\left[ {\frac{{m + n}}{{{p^i}}}} \right] - \left[ {\frac{n}{{{p^i}}}} \right] - \left[ {\frac{m}{{{p^i}}}} \right]} \right)} \)
我们发现上式等同于(m + n)在p进制下进位次数.
我们将A转化为p进制,用f[i][j][k][l]表示处理到i位,p的j次方,是否为边,有无进位组合数个数.
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #define N 3600 5 #define MOD 1000000007 6 #define __min(a,b) (((a)<(b))?(a):(b)) 7 int A[N],p,a,len,n = 0;char B[N];int f[N][N][2][2]; 8 inline int div(char *a,int p) 9 { 10 register int r = 0; 11 for(register int i = len;i;i--) 12 { 13 register long long bak = r * 10LL + a[i]; 14 r = bak % p; 15 a[i] = bak / p; 16 } 17 for(;len && !a[len];len--); 18 return r; 19 } 20 inline int mul(int a,int b){return a * 1ll * b % MOD;} 21 inline int dec(int a,int b){return (a - b + MOD) % MOD;} 22 inline int gp(int c,int r,int nr){if(r) return dec(p,gp(c,0,nr));return c - nr + 1;} 23 inline int gs(int c,int r,int nr) 24 { 25 if(r) return dec(mul(c + 1,p),gs(c,0,nr)); 26 if(c & 1) return dec(mul(c + 2,(c + 1) >> 1),nr * (c + 1)); 27 return dec(mul(c + 1,(c + 2) >> 1),nr * (c + 1)); 28 } 29 inline void inc(int &a,int b){a = (a + b) % MOD;} 30 int main() 31 { 32 scanf("%d %d",&p,&a); 33 scanf("%s",B + 1);len = strlen(B + 1); 34 for(register int i = 1;i <= len;i++)B[i] -= 48; 35 std::reverse(B + 1,B + len + 1);//reverse(B,len); 36 for(;len;)A[++n] = div(B,p); 37 std::reverse(A + 1,A + n + 1);//reverse(A,n); 38 if(a > n){printf("0\n");return 0;} 39 f[1][0][1][0] = 1; 40 for(int register i = 1;i <= n;i++) for(int register j = 0;j <= a;j++) for(int register eq = 0;eq < 2;eq++) for(int register rem = 0;rem < 2;rem++) if(f[i][j][eq][rem]) 41 { 42 int cur = f[i][j][eq][rem]; 43 for(int register nr = 0;nr < 2;nr++) 44 { 45 int register nj = __min(j + nr,a); 46 if(!eq) inc(f[i + 1][nj][eq][nr],mul(cur,gs(p - 1,rem,nr))); 47 else 48 { 49 inc(f[i + 1][nj][eq][nr],mul(cur,gp(A[i],rem,nr))); 50 if (A[i]) inc(f[i + 1][nj][0][nr],mul(cur,gs(A[i] - 1,rem,nr))); 51 } 52 } 53 } 54 int ans = 0;for(int register eq = 0;eq < 2;eq++) inc(ans,f[n + 1][a][eq][0]); 55 printf("%d\n",ans); 56 return 0; 57 }
以上是关于[CF 582D]Number of Binominal Coefficients的主要内容,如果未能解决你的问题,请参考以下文章
CF582D Number of Binominal Coefficients 库默尔定理 数位dp
CF804B Minimum number of steps
CF 466C Number of Ways(数学 / 思维 / DP)