DNA Alignment CodeForces - 520C (思维+快速幂)

DNA Alignment

CodeForces - 520C

Vasya became interested in bioinformatics. He's going to write an article about similar cyclic DNA sequences, so he invented a new method for determining the similarity of cyclic sequences.

Let's assume that strings s and t have the same length n, then the function h(s, t) is defined as the number of positions in which the respective symbols of s and t are the same. Function h(s, t) can be used to define the function of Vasya distance ρ(s, t):

where is obtained from string s, by applying left circular shift i times. For example,
ρ("AGC", "CGT") = 
h("AGC", "CGT") + h("AGC", "GTC") + h("AGC", "TCG") + 
h("GCA", "CGT") + h("GCA", "GTC") + h("GCA", "TCG") + 
h("CAG", "CGT") + h("CAG", "GTC") + h("CAG", "TCG") = 
1 + 1 + 0 + 0 + 1 + 1 + 1 + 0 + 1 = 6

Vasya found a string s of length n on the Internet. Now he wants to count how many strings t there are such that the Vasya distance from the string s attains maximum possible value. Formally speaking, t must satisfy the equation: .

Vasya could not try all possible strings to find an answer, so he needs your help. As the answer may be very large, count the number of such strings modulo 109 + 7.


Input

The first line of the input contains a single integer n (1 ≤ n ≤ 105).

The second line of the input contains a single string of length n, consisting of characters "ACGT".

Output

Print a single number — the answer modulo 109 + 7.

Examples
Input
1
C
Output
1
Input
2
AG
Output
4
Input
3
TTT
Output
1
Note

Please note that if for two distinct strings t1 and t2 values ρ(s, t1) и ρ(s, t2) are maximum among all possible t, then both strings must be taken into account in the answer even if one of them can be obtained by a circular shift of another one.

In the first sample, there is ρ("C", "C") = 1, for the remaining strings t of length 1 the value of ρ(s, t) is 0.

In the second sample, ρ("AG", "AG") = ρ("AG", "GA") = ρ("AG", "AA") = ρ("AG", "GG") = 4.

In the third sample, ρ("TTT", "TTT") = 27

题意:有一个h(s,t)函数,这个函数的函数值是字符串s和t中字符相同的位置的个数。另一个函数




其实就是二重循环内循环字符串s不变,字符串t第一个元素每次移到最后一个,然后求h(),外循环s每次首字符移到最后然后再进行内循环,求这些h()函数总和。就如题目中给的例子

ρ("AGC", "CGT") = 
h("AGC", "CGT") + h("AGC", "GTC") + h("AGC", "TCG") + 
h("GCA", "CGT") + h("GCA", "GTC") + h("GCA", "TCG") + 
h("CAG", "CGT") + h("CAG", "GTC") + h("CAG", "TCG") = 
1 + 1 + 0 + 0 + 1 + 1 + 1 + 0 + 1 = 6

题目让求有多少种t使得这个p()最大



思路:这道题一开始就被题目吓到了,一直到比赛结束也没有想到思路。搜题解发现这是一个找规律的题目,题目让求有多少种t使得这个p()最大,首先我们的任务就是要知道在知道s的情况下p()的最大值是多少

观察发现它的最大值只取决于s字符串中某个出现次数最多的字符个数,为什么这么说呢?

举个例子AAACGT这个字符串我们发现次数最多的是A,那么对于

s:A A A C G T 最大的情况一定是

t:A A A A A A 因为每一个A都可以匹配三次,那么也就是在一次内循环中(t变换时)

每个A可以匹配三次那么一次内循环h()的总和应该是3*n,假如说字符串中有别的字符,那么这个字符在t循环变换的过程中这个字符可以匹配的总次数等于这个字符在s串中的个数,一定小于出现最多的那个次数,比如有C那么t串变化一个循环,C最多可以匹配一次,小于3,那么总的也一定小于3*n;再加上外循环,其实无所谓每次都是3*n,所以是最大值3*n*n。

另外一个例子加入最多出现次数的字符有多个是什么情况呢

s:A A A C C C G T 其实可以这样想,因为这么一个字符串中字符最大出现次数是3

即使有多个出现3的,但是我们t字符串中的字符能和s匹配的字符的最大次数还是3次,不会因为有多个最大出现次数而改变,而会改变的就是我们有了更多的选择方案

为了让p()函数最大,我们就会希望每个字符的匹配次数都是最大值,也就是都是都是s串中字符出现的最大次数,那么我们只要在其中最大出现次数的字符中任选一个即可

s : A A A C C C G T

t:A C C A C A C C

t :  C C A C A A A A

t: _  _ _  _  _  _  _  _

……

所以这样每个字符的再一次变换循环中最大匹配次数都是s中字符出现次数的最大值

所以说到这里估计大家就可以看到大体思路了,每个位置我们又几个最大出现次数的字符就有几种选择x,一共n个位置,总共t可以满足最大值的种类就有x^n中

最终就转化成了求快速幂,哎感叹自己思维辣鸡啊

code:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const int maxn = 1e5+10;
int n;
char s[maxn];
int vis[4];
ll q_pow(ll a, ll b){
    ll ans = 1LL;
    while(b){
        if(b & 1)
            ans = ans * a % mod;
        b >>= 1;
        a = a * a % mod;
    }
    return ans;
}
int main(){
    memset(vis,0,sizeof(vis));
    scanf("%d",&n);
    scanf("%s",s);
    for(int i = 0; i < n; i++){
        if(s[i] == 'A') vis[0]++;
        if(s[i] == 'C') vis[1]++;
        if(s[i] == 'G') vis[2]++;
        if(s[i] == 'T') vis[3]++;
    }
    int maxcnt = 0;
    int cnt = 0;
    for(int i = 0; i < 4; i++){
        maxcnt = max(maxcnt,vis[i]);
    }
    for(int i = 0; i < 4; i++){
        if(vis[i] == maxcnt) cnt++;
    }
    printf("%lld\n",q_pow((ll)cnt,(ll)n));
    return 0;
}

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: NCBI-BLAST-2.13.0-win64是一种基于谷氨酰胺脲和其他生物信息学技术的序列比对软件包。这个软件被广泛用于分析DNA,RNA和蛋白质序列,使得比对过程能够更加快速精确。该软件中包含了多个工具,如核酸和蛋白质序列比对,重排序,序列相似性搜索,基于模板的序列比对等。 NCBI-BLAST-2.13.0-win64具有许多特性和功能,例如可以查询各种序列数据库,对于不同的序列类型具有不同的比对策略,可以进行加速计算和多进程处理,支持多种输出格式,可以进行本地安装等等。此外,其还具有自定义参数和调整比对参数等高级设置。 该软件包已经成为生物医学研究中的重要工具之一,用于生物数据处理、统计学分析以及建立模型和预测。NCBI-BLAST-2.13.0-win64能够帮助研究人员更好的理解生物序列之间的相似性,从而推断其功能和进化关系。这对于进行生物大数据分析和快速挖掘生物信息,为生物医学研究提供更多帮助的重要性无法忽视。 ### 回答2: NCBI-BLAST-2.13.0 -win64 是一款开源软件,是 National Center for Biotechnology Information (NCBI) 提供的序列比对工具之一。该软件适用于 Windows 64 位操作系统,可以在命令行下运行。其中,BLAST 是 Basic Local Alignment Search Tool 的缩写,指的是基本局部比对搜索工具,常用于在大量的生物序列中寻找相似的序列。 NCBI-BLAST-2.13.0 -win64 支持多种输入文件格式,包括 FASTA、GenBank、EMBL 等。它可以对两种或多种序列之间进行 BLAST 分析,查找它们之间的相似性和差异性。与其他序列比对软件相比,NCBI-BLAST-2.13.0 -win64 具有高速度、高准确度、灵活性等特点。此外,它也可以进行多种参数的自定义设置,以适应不同的比对需求。 总之,NCBI-BLAST-2.13.0 -win64 是一款强大的生物信息学工具,可以帮助研究者在大量的生物序列数据中寻找相似的序列,从而推测它们的结构、功能、演化关系等重要信息,为生物学研究提供有力支持。 ### 回答3: ncbi-blast-2.13.0 -win64是一个基于NCBI平台开发的Blast程序的版本号,在Windows操作系统下可用。Blast是一种用于生物信息学研究的算法,用于比对和分析DNA、RNA和蛋白质序列。NCBI-Blast是由美国国家医学图书馆(National Library of Medicine)所提供的一个全球著名的互联网爬虫、文献检索和生物信息资源的网站。NCBI-Blast提供了多个版本,用于不同的平台和操作系统。NCBI-Blast-2.13.0 -win64是专门为Windows 64位操作系统设计开发的版本。它具有以下特点:可以快速比对大规模的DNA、RNA和蛋白质序列;提供多种比对算法,可以根据需要选择适合的算法;支持本地计算机和远程服务器,方便用户按照不同的需求进行使用。总之,NCBI-Blast-2.13.0 -win64是专门为方便Windows 64位用户利用Blast算法比对和分析生物序列而开发的一个工具,可以极大地提高生命科学研究的效率。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值