当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6806:Equal Sentences

题目描述
Sometimes, changing the order of the words in a sentence doesn't influence understanding. For example, if we change "what time is it", into "what time it is"; or change "orz zhang three ak world final", into "zhang orz three world ak final", the meaning of the whole sentence doesn't change a lot, and most people can also understand the changed sentences well.

Formally, we define a sentence as a sequence of words. Two sentences $S$ and $T$ are almost-equal if the two conditions holds:

1. The multiset of the words in $S$ is the same as the multiset of the words in $T$.
2. For a word $\alpha$, its $i^\mathrm{th}$ occurrence in $S$ and its $i^\mathrm{th}$ occurrence in $T$ have indexes differing no more than $1$. (The $k^\mathrm{th}$ word in the sentence has index $k$.) This holds for all $\alpha$ and $i$, as long as the word $\alpha$ appears at least $i$ times in both sentences.

Please notice that "almost-equal" is not a equivalence relation, unlike its name. That is, if sentences $A$ and $B$ are almost-equal, $B$ and $C$ are almost-equal, it is possible that $A$ and $C$ are not almost-equal.

Zhang3 has a sentence $S$ consisting of $n$ words. She wants to know how many different sentences there are, which are almost-equal to $S$, including $S$ itself. Two sentences are considered different, if and only if there is a number $i$ such that the $i^\mathrm{th}$ word in the two sentences are different. As the answer can be very large, please help her calculate the answer modulo $10^9 + 7$.
输入解释
The first line of the input gives the number of test cases, $T \; (1 \le T \le 100)$. $T$ test cases follow.

For each test case, the first line contains an integer $n \; (1 \le n \le 10^5)$, the number of words in the sentence.

The second line contains the sentence $S$ consisting of $n$ words separated by spaces. Each word consists of no more than $10$ lowercase English letters.

The sum of $n$ in all test cases doesn't exceed $2 \times 10^5$.
输出解释
For each test case, print a line with an integer, representing the answer, modulo $10^9 + 7$.
输入样例
2
6
he he zhou is watching you
13
yi yi si wu yi si yi jiu yi jiu ba yao ling
输出样例
8
233
来自杭电HDUOJ的附加信息
Recommend liuyiding

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6806

最后修改于 2020-10-25T23:34:33+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 524288/524288K(Java/Others)