CF744E.Hongcow Masters the Cyclic Shift
NOI/NOI+/CTSC
通过率:0%
时间限制:5.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Hongcow's teacher heard that Hongcow had learned about the cyclic shift, and decided to set the following problem for him.
You are given a list of n strings _s_1, _s_2, ..., s__n contained in the list A.
A list X of strings is called stable if the following condition holds.
First, a message is defined as a concatenation of some elements of the list X. You can use an arbitrary element as many times as you want, and you may concatenate these elements in any arbitrary order. Let S__X denote the set of of all messages you can construct from the list. Of course, this set has infinite size if your list is nonempty.
Call a single message good if the following conditions hold:
- Suppose the message is the concatenation of k strings _w_1, _w_2, ..., w__k, where each w__i is an element of X.
- Consider the |_w_1| + |_w_2| + ... + |w__k| cyclic shifts of the string. Let m be the number of these cyclic shifts of the string that are elements of S__X.
- A message is good if and only if m is exactly equal to k.
The list X is called stable if and only if every element of S__X is good.
Let f(L) be 1 if L is a stable list, and 0 otherwise.
Find the sum of f(L) where L is a nonempty contiguous sublist of A (there are
contiguous sublists in total).
Hongcow 的老师听说 Hongcow 学习了循环移位(cyclic shift)的概念,于是为他设置了如下问题。
给定一个包含 $ n $ 个字符串 $ s_1,,s_2,,\dots,,s_n $ 的列表 $ A $。
称一个字符串列表 $ X $ 是稳定的(stable),当且仅当满足以下条件:
首先,定义一条**消息(message)**为列表 $ X $ 中若干元素的拼接(concatenation)。你可以任意多次使用 $ X $ 中的任意元素,且这些元素的拼接顺序可以任意。记 $ S_X $ 为由列表 $ X $ 能构造出的所有消息组成的集合。显然,只要 $ X $ 非空,该集合的大小即为无穷大。
称一条单个消息是好的(good),当且仅当满足以下条件:
- 设该消息是 $ k $ 个字符串 $ w_1,,w_2,,\dots,,w_k $ 的拼接,其中每个 $ w_i $ 均属于 $ X $;
- 考虑该拼接所得字符串的所有 $ |w_1| + |w_2| + \dots + |w_k| $ 个循环移位(cyclic shifts);令 $ m $ 表示这些循环移位中属于 $ S_X $ 的个数;
- 该消息是“好的”,当且仅当 $ m $ 恰好等于 $ k $。
列表 $ X $ 是稳定的,当且仅当 $ S_X $ 中的每一条消息都是好的。
定义函数 $ f(L) $:若列表 $ L $ 是稳定的,则 $ f(L) = 1 $;否则 $ f(L) = 0 $。
请计算所有非空连续子列表(nonempty contiguous sublist) $ L $ 对应的 $ f(L) $ 之和(列表 $ A $ 共有
个连续子列表)。
输入格式
The first line of input will contain a single integer n (1 ≤ n ≤ 30), denoting the number of strings in the list.
The next n lines will each contain a string s__i (
).
输入的第一行包含一个整数 $ n ( 1 \leq n \leq 30 $),表示列表中字符串的个数。
接下来的 $ n $ 行每行包含一个字符串 $ s_i $(
)。
输出格式
Print a single integer, the number of nonempty contiguous sublists that are stable.
输出一个整数,表示稳定(stable)的非空连续子列表的数量。
输入输出样例
输入#1
4 a ab b bba
输出#1
7
输入#2
5 hh ee ll ll oo
输出#2
0
输入#3
6 aab ab bba b ab c
输出#3
13
说明/提示
For the first sample, there are 10 sublists to consider. Sublists ["a", "ab", "b"], ["ab", "b", "bba"], and ["a", "ab", "b", "bba"] are not stable. The other seven sublists are stable.
For example, X = ["a", "ab", "b"] is not stable, since the message "ab" + "ab" = "abab" has four cyclic shifts ["abab", "baba", "abab", "baba"], which are all elements of S__X.
对于第一个样例,需要考虑 10 个子列表。子列表 ["a", "ab", "b"]、["ab", "b", "bba"] 和 ["a", "ab", "b", "bba"] 不是稳定的。其余七个子列表是稳定的。
例如,X = ["a", "ab", "b"] 不是稳定的,因为消息 "ab" + "ab" = "abab" 有四个循环移位 ["abab", "baba", "abab", "baba"],而这些全部属于 S__X。
输入解题思路,AI测评打分。不知道怎么写?