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. POJ 3468 线段树+状压

    题意:给你n个数,有对区间的加减操作,问某个区间的和是多少. 思路:状压+线段树(要用lazy标记,否则会TLE) //By SiriusRen #include <cstdio> #in ...

  2. SPOJ GSS1 & GSS3&挂了的GSS5

    线段树然后yy一下,搞一搞. GSS1: 题意:求最大区间和. #include <cstdio> #include <algorithm> using namespace s ...

  3. D - Replacement

    Problem description Little Petya very much likes arrays consisting of n integers, where each of them ...

  4. 谈谈对Java中Unicode、编码的理解

    我们经常会遇到编码问题.Java号称国际化的语言,是因为它的class文件采用UTF-8,而JVM运行时使用UTF-16(至于为什么JVM中要采用UTF-16,我没看过 相关的资料,但我猜可能是因为J ...

  5. ORA-03113 ---end-of-file on communication channel 解决方案记录

    ORALCE启动时报如下错误: ORA-03113: end-of-file on communication channel     解决方案如下: 1.查看orcle启动日志,确定具体是什么原因引 ...

  6. GrepWin:Win7下的文本替换工具

    工作环境退回到Win7之后,内容查找功能非常不给力,推荐一个文本内容查找工具grepWin. Win7下的文本查找/替换工具: grepWin

  7. Linux命令小记

    以下说法都是基于普通用户的角度,如果是root,可能会有不同. (1)rm -r或-R选项:递归删除目录及其内容(子目录.文件) rm默认无法删除目录,如果删除空目录,可以使用-d选项.如果目录非空, ...

  8. 【sqli-labs】 less26a GET- Blind based -All you SPACES and COMMENTS belong to us -String-single quotes-Parenthesis(GET型基于盲注的去除了空格和注释的单引号括号注入)

    这个和less26差不多,空格还是用%a0代替,26过了这个也就简单了 ;%00 可以代替注释,尝试一下 order by 3 http://192.168.136.128/sqli-labs-mas ...

  9. struts 2 action result类型

    最近在管理公司老项目的时候发现如下代码: <bean name="detailPlayer" class="PlayAction" method=&quo ...

  10. php第九节课

    面向对象 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 ...