CF156C.Cipher

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Sherlock Holmes found a mysterious correspondence of two VIPs and made up his mind to read it. But there is a problem! The correspondence turned out to be encrypted. The detective tried really hard to decipher the correspondence, but he couldn't understand anything.

At last, after some thought, he thought of something. Let's say there is a word s, consisting of |s| lowercase Latin letters. Then for one operation you can choose a certain position p (1 ≤ p < |s|) and perform one of the following actions:

  • either replace letter s__p with the one that alphabetically follows it and replace letter s__p + 1 with the one that alphabetically precedes it;
  • or replace letter s__p with the one that alphabetically precedes it and replace letter s__p + 1 with the one that alphabetically follows it.

Let us note that letter "z" doesn't have a defined following letter and letter "a" doesn't have a defined preceding letter. That's why the corresponding changes are not acceptable. If the operation requires performing at least one unacceptable change, then such operation cannot be performed.

Two words coincide in their meaning iff one of them can be transformed into the other one as a result of zero or more operations.

Sherlock Holmes needs to learn to quickly determine the following for each word: how many words can exist that coincide in their meaning with the given word, but differs from the given word in at least one character? Count this number for him modulo 1000000007 (109 + 7).

夏洛克·福尔摩斯发现了一封两位重要人物之间的神秘通信,并决心将其破译。但这里有个问题!这封通信被加密了。这位侦探竭尽全力尝试解密,却始终一无所获。

最终,在一番思考之后,他想到了某种规律。假设存在一个由 ∣s∣|s| 个小写拉丁字母组成的单词 ss。那么,一次操作定义为:选择某个位置 pp(其中 1≤p<∣s∣1 \leq p < |s|),并执行以下两种操作之一:

  • 将字母 sps_p 替换为字母表中紧随其后的字母,同时将字母 sp+1s_{p+1} 替换为字母表中紧邻其前的字母;
  • 将字母 sps_p 替换为字母表中紧邻其前的字母,同时将字母 sp+1s_{p+1} 替换为字母表中紧随其后的字母。

注意:“z” 没有定义后续字母,“a” 没有定义前序字母。因此,涉及此类字母的替换是不允许的。若某次操作要求至少执行一次不允许的替换,则该操作不可进行。

当且仅当一个单词可通过零次或多次上述操作变换为另一个单词时,这两个单词语义相同(coincide in their meaning)。

夏洛克·福尔摩斯需要快速判断:对每个给定单词,有多少个与之语义相同的单词(即可通过若干次操作相互转换),但该单词至少在一个字符上与给定单词不同?请帮他计算该数目,并对 10000000071000000007(即 109+710^9 + 7)取模。

输入格式

The input data contains several tests. The first line contains the only integer t (1 ≤ t ≤ 104) — the number of tests.

Next t lines contain the words, one per line. Each word consists of lowercase Latin letters and has length from 1 to 100, inclusive. Lengths of words can differ.

输入数据包含多组测试。第一行包含一个整数 tt(1 ≤ t ≤ 1041 ≤ t ≤ 10^4),表示测试用例的数量。

接下来的 tt 行每行包含一个单词。每个单词均由小写拉丁字母组成,长度在 11 到 100100 之间(含端点)。不同单词的长度可能不同。

输出格式

For each word you should print the number of different other words that coincide with it in their meaning — not from the words listed in the input data, but from all possible words. As the sought number can be very large, print its value modulo 1000000007 (109 + 7).

对于每个单词,你需要输出与其在语义上相同的、不同的其他单词的数量——该数量并非仅限于输入数据中列出的单词,而是针对所有可能的单词。由于所求的数值可能非常大,请输出其对 10000000071000000007(即 109+710^9 + 7)取模的结果。

输入输出样例

  • 输入#1

    1
    ab

    输出#1

    1
  • 输入#2

    1
    aaaaaaaaaaa

    输出#2

    0
  • 输入#3

    2
    ya
    klmbfxzb

    输出#3

    24
    320092793

说明/提示

Some explanations about the operation:

  • Note that for each letter, we can clearly define the letter that follows it. Letter "b" alphabetically follows letter "a", letter "c" follows letter "b", ..., "z" follows letter "y".
  • Preceding letters are defined in the similar manner: letter "y" precedes letter "z", ..., "a" precedes letter "b".
  • Note that the operation never changes a word's length.

In the first sample you can obtain the only other word "ba". In the second sample you cannot obtain any other word, so the correct answer is 0.

Consider the third sample. One operation can transform word "klmbfxzb" into word "klmcexzb": we should choose p = 4, and replace the fourth letter with the following one ("b"  →  "c"), and the fifth one — with the preceding one ("f"  →  "e"). Also, we can obtain many other words from this one. An operation can transform word "ya" only into one other word "xb".

Word "ya" coincides in its meaning with words "xb", "wc", "vd", ..., "ay" (overall there are 24 other words). The word "klmbfxzb has many more variants — there are 3320092814 other words that coincide with in the meaning. So the answer for the first word equals 24 and for the second one equals 320092793 — the number 3320092814 modulo 109 + 7

关于该操作的一些说明:

  • 注意,对于每个字母,我们可以明确定义紧随其后的字母。字母 “b” 在字母表中紧随字母 “a” 之后,字母 “c” 紧随字母 “b” 之后,……,字母 “z” 紧随字母 “y” 之后。
  • 前驱字母以类似方式定义:字母 “y” 是字母 “z” 的前驱,……,字母 “a” 是字母 “b” 的前驱。
  • 注意,该操作永远不会改变单词的长度。

在第一个样例中,你可以唯一地得到另一个单词 “ba”。在第二个样例中,你无法得到任何其他单词,因此正确答案是 0。

考虑第三个样例。一次操作可将单词 “klmbfxzb” 变换为单词 “klmcexzb”:我们应选取 $ p = 4 $,并将第四个字母替换为其后继字母(“b” → “c”),第五个字母替换为其前驱字母(“f” → “e”)。此外,从该单词出发还可得到许多其他单词。一次操作只能将单词 “ya” 变换为唯一另一个单词 “xb”。

单词 “ya” 在含义上与单词 “xb”、“wc”、“vd”、……、“ay”(总计有 24 个其他单词)相同。单词 “klmbfxzb” 则拥有更多变体——与其含义相同的单词共有 3320092814 个。因此,第一个单词的答案为 24,第二个单词的答案为 320092793 —— 即 $ 3320092814 \bmod (10^9 + 7) $。

输入解题思路,AI测评打分。不知道怎么写?

首页