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. Urbanization

    Urbanization time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  2. Copy Constructor的构造操作

    Copy Constructor的构造操作 有三种情况,会以一个object的内容作为另一个class object的初值: 1.  对一个object做显式的初始化操作 class X{…}; X ...

  3. mysql分页的问题

    用过mysql的人肯定知道,mysql提供了原生的分页功能-----LIMIT关键字.LIMIT 子句可以被用于强制 SELECT 语句返回指定的记录数.LIMIT 接受一个或两个数字参数.参数必须是 ...

  4. 在OSchina上看到的清理到缓存的方法

    /* * *文 件 名: DataCleanManager.java * 描 述: 主要功能有清除内/外缓存,清除数据库,清除sharedPreference,清除files和清除自定义目录 */ i ...

  5. nmon的安装与使用

    nmon的安装与使用 1.下载 nmon:http://nmon.sourceforge.net/pmwiki.php?n=Site.Download nmonanalyser http://www. ...

  6. 用js 将long类型转换成日期格式

    //扩展Date的format方法 Date.prototype.format = function (format) { var o = { "M+": this.getMont ...

  7. OpenCV ——背景建模之CodeBook(2)

    1,CodeBook的来源 先考虑平均背景的建模方法.该方法是针对每一个像素,累积若干帧的像素值,然后计算平均值和方差,以此来建立背景模型,相当于模型的每一个像素含有两个特征值,这两个特征值只是单纯的 ...

  8. java和.net的类比

    原文地址在http://www.seguetech.com/blog/2013/06/03/dotnet-vs-java-how-to-pick

  9. 终于购入Mac mini,发现HDMI接口与显示器不兼容,网购了一个VGA转换插头

    Mac mini买到了,最便宜的i5,$647,足够了. 发现路边捡的显示器没有HDMI接口,所以在学校图书馆问了一下IT 技术支持,给我推荐了ebay上$10块钱的转换器. 名字叫 Mini Dis ...

  10. Javascript调用 ActiveXObject导出excel文档。

    function makeDataBook(){ var xls = new ActiveXObject ("Excel.Application"); xls.visible = ...