codeforces 521a//DNA Alignment// Codeforces Round #295(Div. 1)

题意:如题定义的函数,取最大值的数量有多少?

结论只猜对了一半。

首先,如果只有一个元素结果肯定是1.否则。s串中元素数量分别记为a,t,c,g。设另一个串t中数量为a',t',c',g'。那么,固定s串,移动t串时,增加的量为p=a*a'+t*t'+c*c'+g*g'。注意a'+t'+c'+g'是等于串长,那么减少a,t,c,g中最少的对应的那个a',t',c',g',增加到最大的那个上,p值是上升的。而且如果a==t那么a'和t'的数量互换是不影响p值的。因此结论是这种情况下,t串可随意 放出现最多的元素。结果是(一样多且最多的字母个数)^(t长度)

乱码:

//#pragma comment(linker,"/STACK:1024000000,1024000000") 
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include <stack>
#include <list>
using namespace std;
const int SZ=1000010,INF=0x7FFFFFFF;
typedef long long lon;
int num[4];
lon mod=1000000007;

lon pow(lon btn,lon n)
{
    lon res=1,ele=btn;
    for(;n;)
    {
        if(n&1)res*=ele;
        ele*=ele;
        res%=mod;
        ele%=mod;
        n/=2;
    }
    return res;
}

int main()
{
    std::ios::sync_with_stdio(0);
    //freopen("d:\\1.txt","r",stdin); 
    int n;
    cin>>n;
    string str;
    cin>>str;
    num[0]=count(str.begin(),str.end(),'A');
    num[1]=count(str.begin(),str.end(),'T');
    num[2]=count(str.begin(),str.end(),'C');
    num[3]=count(str.begin(),str.end(),'G');
    int maxn=*max_element(num,num+4);
    int maxnum=count(num,num+4,maxn);
    if(maxnum==1)
    {
        cout<<1<<endl;
    }
    else
    {
        cout<<pow((lon)maxnum,(lon)str.size())<<endl;
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/gaudar/p/9652205.html