A9821 | DNA Alignment
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $10^{9}+7$ .
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 $10^{9}+7$ .
输入格式
The first line of the input contains a single integer $n$ ( $1<=n<=10^{5}$ ).
The second line of the input contains a single string of length $n$ , consisting of characters "ACGT".
The second line of the input contains a single string of length $n$ , consisting of characters "ACGT".
输出格式
Print a single number — the answer modulo $10^{9}+7$ .
输入输出样例
输入 #1
1 C
输出 #1
1
输入 #2
2 AG
输出 #2
4
输入 #3
3 TTT
输出 #3
1
Please note that if for two distinct strings $t_{1}$ and $t_{2}$ values $ρ(s,t_{1})$ и $ρ(s,t_{2})$ 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$
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$
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted