DNA

【题目描述】

DNA由A、C、T、G四种碱基构成。现在,科学家们已经知道m种患病基因段,问有多少种不同的长为n的DNA序列是健康的。

【输入描述】

第一行包含两个整数m(0 <= m <= 10)和n(1 <= n <= 2000000000),意义见题目描述;

接下来m行每行1个患病基因片段,长度不超过10。

【输出描述】

输出一个整数,表示有多少长为n的健康DNA序列,若该数字大于100000,则输出其除以100000的余数即可。

【输入样例】

4 3

AT

AC

AG

AA

【输出样例】

36

#include<cmath>
#include<cstdio>
#include<string>
#include<iostream>
using namespace std;
long long m,n,num,lenth[11],ans=1;
string a;
int add1251()
{
    int cur=1;
    for(int i=1;i<=1251;i++)
    {
        cur*=4;
        for(int j=1;j<=10;j++)
        {
            if(lenth[j]!=0)
            {
                cur=cur*(pow(4,j)-lenth[j])/pow(4,j);
                cur%=100000;
            }
        }
    }
    return cur;
}
int main()
{
    scanf("%d%d",&m,&n);
    for(int i=1;i<=m;i++)
    {
        cin>>a;
        lenth[a.size()]++;
    }
    if(n>1253)
    {
        n-=1253;
        for(int i=1;i<=1253;i++)
        {
            ans*=4;
            for(int j=1;j<=10;j++)
            {
                if(lenth[j]!=0)
                {
                    ans=ans*(pow(4,j)-lenth[j])/pow(4,j);
                    ans%=100000;
                }
            }
        }
    }
    else
    {
        int i=0;
        while(n--)
        {
            i++;
            ans*=4;
            for(int j=1;j<=10;j++)
            {
                if(lenth[j]!=0&&i>=j)
                {
                    ans=ans*(pow(4,j)-lenth[j])/pow(4,j);
                    ans%=100000;
                }
            }
        }
    }
    int t=(n-n%1251)/1251;
    if(t>0) ans=ans*add1251()*t%100000;
    n%=1251;
    if(n>0)
    {
        while(n--)
        {
            ans*=4;
            for(int j=1;j<=10;j++)
            {
                if(lenth[j]!=0)
                {
                    ans=ans*(pow(4,j)-lenth[j])/pow(4,j);
                    ans%=100000;
                }
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}

 

posted @ 2016-09-10 16:19  前前前世。  阅读(212)  评论(0编辑  收藏  举报