HDU 2065 "红色病毒"问题 (泰勒级数推导)
转载请注明出处,谢谢 http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove
题源:http://acm.hdu.edu.cn/showproblem.php?pid=2065
比赛的时候遇到这种题,只能怪自己高数学得不好,看着别人秒。。。。
由4种字母组成,A和C只能出现偶数次。
构造指数级生成函数:(1+x/1!+x^2/2!+x^3/3!……)^2*(1+x^2/2!+x^4/4!+x^6/6!……)^2.
前面是B和D的情况,可以任意取,但是相同字母一样,所以要除去排列数。后者是A和C的情况,只能取偶数个情况。
根据泰勒展开,e^x在x0=0点的n阶泰勒多项式为 1+x/1!+x^2/2!+x^3/3!……
而后者也可以进行调整,需要把奇数项去掉,则e^(-x)的展开式为1-x/1!+X^2/2!-X^3/3!……
所以后者可以化简为(e^x+e^(-x))/2。则原式为(e^x)^2 * ((e^x*e^(-x))/2)^2
整理得到e^4x+2*e^2x+1。
又由上面的泰勒展开
e^4x = 1 + (4x)/1! + (4x)^2/2! + (4x)^3/3! + ... + (4x)^n/n!;
e^2x = 1 + (2x)/1! + (2x)^2/2! + (2x)^3/3! + ... + (2x)^n/n!;
对于系数为n的系数为(4^n+2*2^n)/4=4^(n-1)+2^(n-1);
快速幂搞之。
#include<iostream>#include<cstdio>#include<cstring>#include<queue>#include<vector>#include<cmath>#define LL long long#define MOD 100#define eps 1e-6#define N 100010#define zero(a) fabs(a)<epsusing namespace std;int PowMod(int a,LL b){int ret=1;while(b){if(b&1)ret=(ret*a)%MOD;a=(a*a)%MOD;b>>=1;}return ret;}int main(){int t;while(scanf("%d",&t)!=EOF&&t){int cas=0;LL n;while(t--){scanf("%I64d",&n);printf("Case %d: %d\n",++cas,(PowMod(4,n-1)+PowMod(2,n-1))%MOD);}printf("\n");}return 0;}