首页 > 其他分享 >hdu:"红色病毒"问题(指数型母函数用e^x指数函数来计算)

hdu:"红色病毒"问题(指数型母函数用e^x指数函数来计算)

时间:2023-01-27 18:22:59浏览次数:38  
标签:Case hdu int ll 指数函数 型母 字符串 病毒 mod

Problem Description
医学界发现的新病毒因其蔓延速度和Internet上传播的”红色病毒”不相上下,被称为”红色病毒”,经研究发现,该病毒及其变种的DNA的一条单链中,胞嘧啶,腺嘧啶均是成对出现的。
现在有一长度为N的字符串,满足一下条件:
(1) 字符串仅由A,B,C,D四个字母组成;
(2) A出现偶数次(也可以不出现);
(3) C出现偶数次(也可以不出现);
计算满足条件的字符串个数.
当N=2时,所有满足条件的字符串有如下6个:BB,BD,DB,DD,AA,CC.
由于这个数据肯能非常庞大,你只要给出最后两位数字即可.

Input
每组输入的第一行是一个整数T,表示测试实例的个数,下面是T行数据,每行一个整数N(1<=N<2^64),当T=0时结束.

Output
对于每个测试实例,输出字符串个数的最后两位,每组输出后跟一个空行.


输入样例

4
1
4
20
11
3
14
24
6
0

输出样例

Case 1: 2
Case 2: 72
Case 3: 32
Case 4: 0

Case 1: 56
Case 2: 72
Case 3: 56

关键是各项的表示,只能出现偶数次用(e^x+e^-x)/2来表示,最后只提取n次项前的系数
另一个注意快速幂的写法,a和ans都有及时取模
#include<bits/stdc++.h>
using namespace std;
const int mod=100;
typedef long long ll;
int pow_qui(int a,ll k)
{
    ll ans=1;
    for(;k;k>>=1)
    {
        if(k&1) ans*=a,ans%=mod;
        a*=a;
        a%=mod;
    }
    return ans%mod;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll T,n;
    while(cin>>T,T)
    {
    for(int i=1;i<=T;++i)
    {
        cin>>n;
        int ans1=pow_qui(2,n-1);
        int ans2=pow_qui(4,n-1);
        cout<<"Case "<<i<<": ";
        cout<<(ans1+ans2)%mod<<'\n';
    }
    cout<<'\n';
    }
    return 0;
}

 

 

标签:Case,hdu,int,ll,指数函数,型母,字符串,病毒,mod
From: https://www.cnblogs.com/ruoye123456/p/17069133.html

相关文章

  • hdu:The Balance(母函数)
    ProblemDescriptionNowyouareaskedtomeasureadoseofmedicinewithabalanceandanumberofweights.Certainlyitisnotalwaysachievable.Soyoushou......
  • hdu4135
    求[a,b]中与n互素的数字个数  #include<iostream>#include<algorithm>usingnamespacestd;constintN=200;#defineintlonglonginttot,fac[N];......
  • hdu:Kiki & Little Kiki 2(矩阵快速幂)
    ProblemDescriptionTherearenlightsinacirclenumberedfrom1ton.Theleftoflight1islightn,andtheleftoflightk(1<k<=n)isthelightk-1.A......
  • hdu:Simpsons’ Hidden Talents(kmp)
    ProblemDescriptionHomer:Marge,Ijustfiguredoutawaytodiscoversomeofthetalentsweweren’tawarewehad.Marge:Yeah,whatisit?Homer:Takemefor......
  • hdu:Big Event in HDU(母函数,背包)
    ProblemDescriptionNowadays,weallknowthatComputerCollegeisthebiggestdepartmentinHDU.But,maybeyoudon’tknowthatComputerCollegehadeverbe......
  • hdu:剪花布条(kmp)
    ProblemDescription一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案。对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢?Input......
  • HDU 6157 The Karting
    题目传送门TheKarting思路分析序列上的路径问题,可以转化成起点和终点的匹配问题,dp匹配的权值,记录匹配的标记就可做数据很小,支持\(O(n^3)\)看起来可以直接dp引入......
  • hdu:Holding Bin-Laden Captive(母函数,数学)
    ProblemDescriptionWeallknowthatBin-Ladenisanotoriousterrorist,andhehasdisappearedforalongtime.Butrecently,itisreportedthathehidesin......
  • hdu:Ignatius and the Princess III(母函数)
    ProblemDescription“Well,itseemsthefirstproblemistooeasy.Iwillletyouknowhowfoolishyouarelater.”feng5166says.“Thesecondproblemis,g......
  • hdu:Another kind of Fibonacci(含多种关系的矩阵快速幂)
    ProblemDescriptionAsweallknown,theFibonacciseries:F(0)=1,F(1)=1,F(N)=F(N-1)+F(N-2)(N>=2).NowwedefineanotherkindofFibonacci:......