C. Reberland Linguistics
 
 

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
 
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的(只要在5后面)后半段分为只含三个或者两个的字母的连续后缀

  后缀:满足不连续相同可以间隔相同;

  将所有满足条件的分法的所有后缀放入集合,按字典序输出

题解:

  

#include<bits/stdc++.h>
using namespace std;
const int N = 1e4+, M = 1e6+, mod = 1e9+, inf = 1e9+;
typedef long long ll; char a[N];
set<string > s;
int f[N][];//i开始到l是否可行
int main() {
scanf("%s",a);
int n = strlen(a);
a[n] = '';
a[n+] ='';
a[n+] = '';
if(n<=) {
cout<<<<endl;
return ;
}
if(n->=) {
string tmp;
tmp = tmp + a[n-]+ a[n-];
s.insert(tmp);
f[n-][] = ;
}
if(n->=) {
string tmp;
tmp = tmp + a[n-]+ a[n-]+ a[n-];
s.insert(tmp);
f[n-][] = ;
}
for(int i=n-;i>=;i--) {
string s1 = "",s2 = "";
s1 = s1 + a[i] + a[i+];
s2 = s2 + a[i+] + a[i+];
if((s1!=s2&&f[i+][])||f[i+][]) {
f[i][] = ;
s.insert(s1);//cout<<s1<<endl;
}
if(i+<n) {
s1 = "",s2 = "";
s1 = s1 + a[i] + a[i+] + a[i+];
s2 = s2 + a[i+] + a[i+] + a[i+];
if((s1!=s2&&f[i+][])||f[i+][]) {
f[i][] = ;
s.insert(s1);
//cout<<s1<<endl;
}
}
}
cout<<s.size()<<endl;
for(set<string > ::iterator it=s.begin();it!=s.end();it++) cout<<(*it)<<endl;
return ;
}

Codeforces Round #349 (Div. 2) C. Reberland Linguistics DP+set的更多相关文章

  1. Codeforces Round #349 (Div. 1) A. Reberland Linguistics dp

    题目链接: 题目 A. Reberland Linguistics time limit per test:1 second memory limit per test:256 megabytes 问 ...

  2. Codeforces Round #349 (Div. 1) A. Reberland Linguistics 动态规划

    A. Reberland Linguistics 题目连接: http://www.codeforces.com/contest/666/problem/A Description First-rat ...

  3. Codeforces Round #349 (Div. 2) C. Reberland Linguistics (DP)

    C. Reberland Linguistics time limit per test 1 second memory limit per test 256 megabytes input stan ...

  4. Codeforces Round #174 (Div. 1) B. Cow Program(dp + 记忆化)

    题目链接:http://codeforces.com/contest/283/problem/B 思路: dp[now][flag]表示现在在位置now,flag表示是接下来要做的步骤,然后根据题意记 ...

  5. Codeforces Round #349 (Div. 1) B. World Tour 最短路+暴力枚举

    题目链接: http://www.codeforces.com/contest/666/problem/B 题意: 给你n个城市,m条单向边,求通过最短路径访问四个不同的点能获得的最大距离,答案输出一 ...

  6. Codeforces Round #349 (Div. 2) D. World Tour (最短路)

    题目链接:http://codeforces.com/contest/667/problem/D 给你一个有向图,dis[i][j]表示i到j的最短路,让你求dis[u][i] + dis[i][j] ...

  7. Codeforces Round #349 (Div. 1) B. World Tour 暴力最短路

    B. World Tour 题目连接: http://www.codeforces.com/contest/666/problem/B Description A famous sculptor Ci ...

  8. Codeforces Round #349 (Div. 1)E. Forensic Examination

    题意:给一个初始串s,和m个模式串,q次查询每次问你第l到第r个模式串中包含\(s_l-s_r\)子串的最大数量是多少 题解:把初始串和模式串用分隔符间隔然后建sam,我们需要找到在sam中表示\(s ...

  9. Codeforces Round #349 (Div. 2)

    第一题直接算就行了为了追求手速忘了输出yes导致wa了一发... 第二题技巧题,直接sort,然后把最大的和其他的相减就是构成一条直线,为了满足条件就+1 #include<map> #i ...

随机推荐

  1. 计算某个时间段(2017-10-01 2017-12-01)内svn更新文件的MD5

    #!/bin/sh svn up svn log -v -r {$1}:{$2} | grep / | grep -v xxx | sort -f -u | uniq | awk -F 'xxxx' ...

  2. POJ1915 BFS&双向BFS

    俩月前写的普通BFS #include <cstdio> #include <iostream> #include <cstring> #include <q ...

  3. [SGU 199] Beautiful People

    [SGU 199] Beautiful People The most prestigious sports club in one city has exactly N members. Each ...

  4. mybatis parameterType报错:There is no getter for property named 'xxx' in 'class java.lang.String'

    方法1: 当parameterType = "java.lang.String" 的时候,参数读取的时候必须为 _parameter 方法2: 在dao层的时候,设置一下参数,此方 ...

  5. Spring Boot (16) logback和access日志

    Spring Boot 内部采用的是Commons Logging进行日志记录,但是在底层为Java Util Logging.Log4J2.Logback等日志框架提供了默认配置. logback ...

  6. Rabbit--ack机制

    消息应答时执行一个任务可能需要花费几秒钟,你可能会担心如果一个消费者在执行任务过程中挂掉了. 一旦RabbitMQ将消息分发给了消费者,就会从内存中删除.在这种情况下,如果正在执行任务的消费者宕机,会 ...

  7. windows phone传感器

    Windows phone中的传感器主要包括加速计传感器.罗盘传感器.陀螺仪传感器等 加速计传感器 Accelerometer类是加速传感器的接口,Accelerometer类位于Windows.De ...

  8. c# 读取 XML

    XmlDocument xmldoc = new XmlDocument(); string xmlPath = HttpContext.Server.MapPath("~/*****.xm ...

  9. POJ_2594_最小路径覆盖

    Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 8085   Accepted: 3 ...

  10. maven将jar包添加到本地仓库

    mvn install:install-file -Dfile=jar包本地路径 -DgroupId=groupID -DartifactId=ifactId -Dversion=版本 -Dpacka ...