A15717 | Serval and Brain Power
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Serval loves Brain Power and his brain power problem.
Serval defines that a string $T$ is powerful iff $T$ can be obtained by concatenating some string $T'$ multiple times. Formally speaking, $T$ is powerful iff there exist a string $T'$ and an integer $k\geq 2$ such that
$$ T=\underbrace{T'+T'+\dots+T'}_{k\text{ times}} $$
For example, $\texttt{gogogo}$ is powerful because it can be obtained by concatenating $\texttt{go}$ three times, but $\texttt{power}$ is not powerful.
Serval has a string $S$ consists of lowercase English letters. He is curious about the longest powerful subsequence of $S$ , and he only needs you to find out the length of it. If all the non-empty subsequences of $S$ is not powerful, the answer is considered to be $0$ .
A string $a$ is a subsequence of a string $b$ if $a$ can be obtained from $b$ by the deletion of several (possibly, zero or all) characters.
Serval defines that a string $T$ is powerful iff $T$ can be obtained by concatenating some string $T'$ multiple times. Formally speaking, $T$ is powerful iff there exist a string $T'$ and an integer $k\geq 2$ such that
$$ T=\underbrace{T'+T'+\dots+T'}_{k\text{ times}} $$
For example, $\texttt{gogogo}$ is powerful because it can be obtained by concatenating $\texttt{go}$ three times, but $\texttt{power}$ is not powerful.
Serval has a string $S$ consists of lowercase English letters. He is curious about the longest powerful subsequence of $S$ , and he only needs you to find out the length of it. If all the non-empty subsequences of $S$ is not powerful, the answer is considered to be $0$ .
A string $a$ is a subsequence of a string $b$ if $a$ can be obtained from $b$ by the deletion of several (possibly, zero or all) characters.
输入格式
The first line contains a single string $S$ ( $|S|\leq 80$ ) consisting of lowercase English letters.
输出格式
Print a single integer — the length of the longest powerful subsequence of $S$ . If all the non-empty subsequences of $S$ is not powerful, print $0$ .
输入输出样例
输入 #1
buaa
输出 #1
2
输入 #2
codeforcesround
输出 #2
6
输入 #3
oooooooooooaaaaeaaiaujooooooooooooo
输出 #3
24
输入 #4
zero
输出 #4
0
For the first sample, all of the non-empty subsequences of buaa are listed below:
- b
- u
- a (occurred twice, buaa and buaa)
- bu
- ba (occurred twice, buaa and buaa)
- ua (occurred twice, buaa and buaa)
- aa
- bua (occurred twice, buaa and buaa )
- baa
- uaa
- buaa
Since $\texttt{aa} = \texttt{a} + \texttt{a}$ , aa is a powerful subsequence. It can be shown that aa is the only powerful subsequence among them. So the answer is $2$ .
For the second sample, the longest powerful subsequence is codcod from codeforcesround. So the answer is $6$ .
- b
- u
- a (occurred twice, buaa and buaa)
- bu
- ba (occurred twice, buaa and buaa)
- ua (occurred twice, buaa and buaa)
- aa
- bua (occurred twice, buaa and buaa )
- baa
- uaa
- buaa
Since $\texttt{aa} = \texttt{a} + \texttt{a}$ , aa is a powerful subsequence. It can be shown that aa is the only powerful subsequence among them. So the answer is $2$ .
For the second sample, the longest powerful subsequence is codcod from codeforcesround. So the answer is $6$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted