zoukankan      html  css  js  c++  java
  • 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
    ",ans);
        return 0;
    }
  • 相关阅读:
    P2730 魔板 Magic Squares
    P2124 奶牛美容
    4. Median of Two Sorted Arrays(Array; Divide-and-Conquer)
    3.Longest Substring Without Repeating Characters(string; HashTable)
    2.Add Two Numbers (List)
    1.Two Sum (Array; HashTable)
    C++中的浅拷贝、深拷贝、智能指针
    C++ 静态数据成员和静态成员函数
    C & C++ 宏与const
    C++指针与引用
  • 原文地址:https://www.cnblogs.com/Ackermann/p/5859631.html
Copyright © 2011-2022 走看看