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.

写了两天,才搞定。

in a row 是后来才注意到的,但是我还是认为不会影响什么,一直认为以前出现过就不行,最后问了学姐,给了一组样例。

zzzzz cf aaa aa aaa,不能出现相邻的相同的。

一下子考虑四个或者六个。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
using namespace std;
const int maxn = 1e4+;
int dp[maxn][];
set<string>ans;
int main()
{
string s;
cin>>s;
int n = s.size();
if(n<=)
{
printf("0\n");
return ;
}
if(n>=)
{
string s1="";
s1 = s1+s[n-]+s[n-];
ans.insert(s1);
dp[n-][] = ;
}
if(n>=)
{
string s1;
s1 = s1+s[n-]+s[n-]+s[n-];
ans.insert(s1);
dp[n-][] = ;
}
for(int i=n-;i>=;i--)
{
string s1="",s2 = "";
s1 = s1+s[i]+s[i+];
s2 = s2+s[i+]+s[i+];
// cout<<s1<<endl;
// cout<<s2<<endl;
if((s1!=s2&&dp[i+][])||dp[i+][])
{
dp[i][] = ;
ans.insert(s1);
// cout<<s1<<endl;
}
s1 = "";
s2 = "";
s1 = s1+s[i]+s[i+]+s[i+];
// cout<<s1<<endl;
s2 = s2+s[i+]+s[i+]+s[i+];
if((s1!=s2&&dp[i+][])||dp[i+][])
{
dp[i][] = ;
ans.insert(s1);
// cout<<s1<<endl;
}
}
printf("%d\n",ans.size());
for(set<string>::iterator it = ans.begin();it!=ans.end();it++)
{
cout<<*it<<endl;
}
return ;
}

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

  1. Codeforces Round #367 (Div. 2) C. Hard problem(DP)

    Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...

  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. 1) A. Reberland Linguistics dp

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

  4. Codeforces Round #349 (Div. 2) C. Reberland Linguistics DP+set

    C. Reberland Linguistics     First-rate specialists graduate from Berland State Institute of Peace a ...

  5. Codeforces Round #369 (Div. 2) C. Coloring Trees(dp)

    Coloring Trees Problem Description: ZS the Coder and Chris the Baboon has arrived at Udayland! They ...

  6. Codeforces Round #245 (Div. 1) B. Working out (dp)

    题目:http://codeforces.com/problemset/problem/429/B 第一个人初始位置在(1,1),他必须走到(n,m)只能往下或者往右 第二个人初始位置在(n,1),他 ...

  7. Codeforces Round #260 (Div. 1) 455 A. Boredom (DP)

    题目链接:http://codeforces.com/problemset/problem/455/A A. Boredom time limit per test 1 second memory l ...

  8. Codeforces Round #369 (Div. 2) C. Coloring Trees (DP)

    C. Coloring Trees time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  9. Codeforces Round #552 (Div. 3) F. Shovels Shop(dp)

    题目链接 大意:给你n个物品和m种优惠方式,让你买k种,问最少多少钱. 思路:考虑dpdpdp,dp[x]dp[x]dp[x]表示买xxx种物品的最少花费,然后遍历mmm种优惠方式就行转移就好了. # ...

随机推荐

  1. 转 shell awk 使用详解

    awk简介 awk: 中文意思是报告生成器 能够根据我们输入的信息,将信息格式化以后显示,将定义好的信息以比较美观(直观)的方式显示出来出现比较早,继而出现了new awk(nawk)在windows ...

  2. 笨方法学python--提示别人

    1 上次学到使用raw_input(), 还可以如下使用: age = raw_input("age?") 2 命令名查看raw_input的说明 unit, pydoc raw_ ...

  3. CF/div2c/贪心

    题目链接[http://codeforces.com/contest/749/problem/C] 题意:给出一个长度为n序列包含D和R,每一轮操作的先后顺序是1-n,规则是每一轮每个人有一次机会杀掉 ...

  4. ACE_Message_Block消息数据类

    ACE_Message_Block ACE_Message_Block用于构建"固定"和"可变"长度的消息.ACE_Message_Block可以将多条消息连接 ...

  5. git(创建,提交,回退)

    创建版本库 2334次阅读 什么是版本库呢?版本库又名仓库,英文名repository,你可以简单理解成一个目录,这个目录里面的所有文件都可以被Git管理起来,每个文件的修改.删除,Git都能跟踪,以 ...

  6. hdu_5695_Gym Class(拓扑排序)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5695 题意:中文题,不解释 题解:逆向拓扑字典序就行 #include<cstdio> # ...

  7. PHP:class static

    简介 static关键词的一种常见用途是,当类的某个变量$var被定义为static时,那么$var就是类的变量. 这意味着:1,该类的任意一个实例对其进行修改,在该类的其它实例中访问到的是修改后的变 ...

  8. jquery多级下拉菜单

    var menu = new Click('#menu',{target:'p',parent:'li',contr:'ul',way:0}); /* 参数说明: target : 点击事件发生在该元 ...

  9. Linux Ubuntu 内核升级

    方法一 : 1 更新系统源 apt-get update 2 搜索内核文件 apt-cache search linux-image 3 安装 apt-get install -y  linux-im ...

  10. Codeforces Round #372 (Div. 2) C 数学

    http://codeforces.com/contest/716/problem/C 题目大意:感觉这道题还是好懂得吧. 思路:不断的通过列式子的出来了.首先我们定义level=i, uplevel ...