CROC 2016 - Elimination Round
E
Intellectual Inquiry
Codeforces
2200
原题
← DF →
翻译中…

After getting kicked out of her reporting job for not knowing the alphabet, Bessie has decided to attend school at the Fillet and Eggs Eater Academy. She has been making good progress with her studies and now knows the first $*k*$ English letters.

翻译中…

Each morning, Bessie travels to school along a sidewalk consisting of $*m* + *n*$ tiles. In order to help Bessie review, Mr. Moozing has labeled each of the first $*m*$ sidewalk tiles with one of the first $*k*$ lowercase English letters, spelling out a string $*t*$. Mr. Moozing, impressed by Bessie's extensive knowledge of farm animals, plans to let her finish labeling the last $*n*$ tiles of the sidewalk by herself.

翻译中…

Consider the resulting string $*s*$ ($|*s*| = *m* + *n*$) consisting of letters labeled on tiles in order from home to school. For any sequence of indices $*p*_{1} < *p*_{2} < ... < *p*_{*q*}$ we can define subsequence of the string $*s*$ as string $*s*_{*p*_{1}}*s*_{*p*_{2}}... *s*_{*p*_{*q*}}$. Two subsequences are considered to be distinct if they differ as strings. Bessie wants to label the remaining part of the sidewalk such that the number of distinct subsequences of tiles is maximum possible. However, since Bessie hasn't even finished learning the alphabet, she needs your help!

翻译中…

Note that empty subsequence also counts.

翻译中…

Input

翻译中…

The first line of the input contains two integers $*n*$ and $*k*$ ($0 ≤ *n* ≤ 1 000 000$, $1 ≤ *k* ≤ 26$).

翻译中…

The second line contains a string $*t*$ ($|*t*| = *m*, 1 ≤ *m* ≤ 1 000 000$) consisting of only first $*k*$ lowercase English letters.

翻译中…

Output

翻译中…

Determine the maximum number of distinct subsequences Bessie can form after labeling the last $*n*$ sidewalk tiles each with one of the first $*k*$ lowercase English letters. Since this number can be rather large, you should print it modulo $10^{9} + 7$.

翻译中…

Please note, that you are not asked to maximize the remainder modulo $10^{9} + 7$! The goal is to maximize the initial value and then print the remainder.

翻译中…

Note

翻译中…

In the first sample, the optimal labeling gives $8$ different subsequences: "" (the empty string), "a", "c", "b", "ac", "ab", "cb", and "acb".

翻译中…

image

翻译中…

In the second sample, the entire sidewalk is already labeled. The are $10$ possible different subsequences: "" (the empty string), "a", "b", "aa", "ab", "ba", "aaa", "aab", "aba", and "aaba". Note that some strings, including "aa", can be obtained with multiple sequences of tiles, but are only counted once.

翻译中…

样例

Input #1
1 3
ac
Output #1
8
InputCopy OutputCopy
Input #2
0 2
aaba
Output #2
10
InputCopy OutputCopy
题目信息
题号
645E
时间限制
2 s
内存限制
256 MB
标签
动态规划
贪心
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。