A10683 | Bacterial Melee
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Julia is conducting an experiment in her lab. She placed several luminescent bacterial colonies in a horizontal testtube. Different types of bacteria can be distinguished by the color of light they emit. Julia marks types of bacteria with small Latin letters "a", ..., "z".
The testtube is divided into $n$ consecutive regions. Each region is occupied by a single colony of a certain bacteria type at any given moment. Hence, the population of the testtube at any moment can be described by a string of $n$ Latin characters.
Sometimes a colony can decide to conquer another colony in one of the adjacent regions. When that happens, the attacked colony is immediately eliminated and replaced by a colony of the same type as the attacking colony, while the attacking colony keeps its type. Note that a colony can only attack its neighbours within the boundaries of the testtube. At any moment, at most one attack can take place.
For example, consider a testtube with population "babb". There are six options for an attack that may happen next:
- the first colony attacks the second colony ( $1→2$ ), the resulting population is "bbbb";
- $2→1$ , the result is "aabb";
- $2→3$ , the result is "baab";
- $3→2$ , the result is "bbbb" (note that the result is the same as the first option);
- $3→4$ or $4→3$ , the population does not change.
The pattern of attacks is rather unpredictable. Julia is now wondering how many different configurations of bacteria in the testtube she can obtain after a sequence of attacks takes place (it is possible that no attacks will happen at all). Since this number can be large, find it modulo $10^{9}+7$ .
The testtube is divided into $n$ consecutive regions. Each region is occupied by a single colony of a certain bacteria type at any given moment. Hence, the population of the testtube at any moment can be described by a string of $n$ Latin characters.
Sometimes a colony can decide to conquer another colony in one of the adjacent regions. When that happens, the attacked colony is immediately eliminated and replaced by a colony of the same type as the attacking colony, while the attacking colony keeps its type. Note that a colony can only attack its neighbours within the boundaries of the testtube. At any moment, at most one attack can take place.
For example, consider a testtube with population "babb". There are six options for an attack that may happen next:
- the first colony attacks the second colony ( $1→2$ ), the resulting population is "bbbb";
- $2→1$ , the result is "aabb";
- $2→3$ , the result is "baab";
- $3→2$ , the result is "bbbb" (note that the result is the same as the first option);
- $3→4$ or $4→3$ , the population does not change.
The pattern of attacks is rather unpredictable. Julia is now wondering how many different configurations of bacteria in the testtube she can obtain after a sequence of attacks takes place (it is possible that no attacks will happen at all). Since this number can be large, find it modulo $10^{9}+7$ .
输入格式
The first line contains an integer $n$ — the number of regions in the testtube ( $1<=n<=5000$ ).
The second line contains $n$ small Latin letters that describe the initial population of the testtube.
The second line contains $n$ small Latin letters that describe the initial population of the testtube.
输出格式
Print one number — the answer to the problem modulo $10^{9}+7$ .
输入输出样例
输入 #1
3 aaa
输出 #1
1
输入 #2
2 ab
输出 #2
3
输入 #3
4 babb
输出 #3
11
输入 #4
7 abacaba
输出 #4
589
In the first sample the population can never change since all bacteria are of the same type.
In the second sample three configurations are possible: "ab" (no attacks), "aa" (the first colony conquers the second colony), and "bb" (the second colony conquers the first colony).
To get the answer for the third sample, note that more than one attack can happen.
In the second sample three configurations are possible: "ab" (no attacks), "aa" (the first colony conquers the second colony), and "bb" (the second colony conquers the first colony).
To get the answer for the third sample, note that more than one attack can happen.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted