zoukankan      html  css  js  c++  java
  • hdu 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);

    快速幂搞之。

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<queue>
     5 #include<vector>
     6 #include<cmath>
     7 #define LL  long long
     8 #define MOD 100
     9 #define eps 1e-6
    10 #define N 100010
    11 #define zero(a)  fabs(a)<eps
    12 using namespace std;
    13 int PowMod(int a,LL b){
    14     int ret=1;
    15     while(b){
    16         if(b&1)
    17             ret=(ret*a)%MOD;
    18         a=(a*a)%MOD;
    19         b>>=1;
    20     }
    21     return ret;
    22 }
    23 int main(){
    24     int t;
    25     while(scanf("%d",&t)!=EOF&&t){
    26         int cas=0;
    27         LL n;
    28         while(t--){
    29             scanf("%I64d",&n);
    30             printf("Case %d: %d
    ",++cas,(PowMod(4,n-1)+PowMod(2,n-1))%MOD);
    31         }
    32         printf("
    ");
    33     }
    34     return 0;
    35 }
  • 相关阅读:
    每天一道LeetCode--141.Linked List Cycle(链表环问题)
    每天一道LeetCode--119.Pascal's Triangle II(杨辉三角)
    每天一道LeetCode--118. Pascal's Triangle(杨辉三角)
    CF1277D Let's Play the Words?
    CF1281B Azamon Web Services
    CF1197D Yet Another Subarray Problem
    CF1237D Balanced Playlist
    CF1239A Ivan the Fool and the Probability Theory
    CF1223D Sequence Sorting
    CF1228D Complete Tripartite
  • 原文地址:https://www.cnblogs.com/unknownname/p/9391392.html
Copyright © 2011-2022 走看看