C. Reberland Linguistics time limit per test
1 second memory limit per test
256 megabytes input
standard input output
standard output First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other.
For example, you should know linguistics very well. You learn a structure of Reberland language as foreign language. In this language words are constructed according to the following rules. First you need to choose the "root" of the word — some string which has more than 4 letters. Then several strings with the length 2 or 3 symbols are appended to this word. The only restriction — it is not allowed to append the same string twice in a row. All these strings are considered to be suffixes of the word (this time we use word "suffix" to describe a morpheme but not the few last characters of the string as you may used to).
Here is one exercise that you have found in your task list. You are given the word s. Find all distinct strings with the length 2 or 3, which can be suffixes of this word according to the word constructing rules in Reberland language.
Two strings are considered distinct if they have different length or there is a position in which corresponding characters do not match.
Let's look at the example: the word abacabaca is given. This word can be obtained in the following ways:
文章图片
, where the root of the word is overlined, and suffixes are marked by "corners". Thus, the set of possible suffixes for this word is {aca,?ba,?ca}.
Input The only line contains a string s (5?≤?|s|?≤?104) consisting of lowercase English letters.
Output On the first line print integer k — a number of distinct possible suffixes. On the next k lines print suffixes.
Print suffixes in lexicographical (alphabetical) order.
Examples input
abacabaca
output
3 aca ba ca
input
abaca
output
0
Note The first test was analysed in the problem statement.
In the second example the length of the string equals 5. The length of the root equals 5, so no string can be used as a suffix.
题意:给出一个字符串字符串最前面的不小于5个字符为这个字符串的根,剩下的由2个或3个字符组成的字符串构成并且相同的字符串不能连续出现两次。问最后的字符串的种类个数,并按照字典序输出。
【667C - Reberland Linguistics【dp】】
/* ***********************************************
Author: ryc
Created Time : 2016-08-07 Sunday
File Name: E:\acm\codeforces\677C.cpp
Language: c++
Copyright 2016 ryc All Rights Reserved
************************************************ */
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
推荐阅读
- 技术|为参加2021年蓝桥杯Java软件开发大学B组细心整理常见基础知识、搜索和常用算法解析例题(持续更新...)
- 数据结构与算法|【算法】力扣第 266场周赛
- #|算法设计与分析(Java实现)—— 动态规划 (0-1 背包问题)
- 动态规划|暴力递归经典问题
- 动态规划|动态规划 —— 状压DP (附一些位运算小知识)
- 区间DP —— 能量项链
- 动态规划 —— 区间DP
- Codeforces|Codeforces Round #605 (Div. 3) D. Remove One Element
- LeetCode-28 实现strStr() KMP算法
- leetcode|递归、动态规划--Leetcode(python)