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;
}

 

转载于:https://www.cnblogs.com/gaudar/p/9652205.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值