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. http接口 两种调用http接口的方法

    import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.NameValuePair; ...

  2. oracle从入门到精通复习笔记续集之PL/SQL(轻量版)

    复习内容: PL/SQL的基本语法.记录类型.流程控制.游标的使用. 异常处理机制.存储函数/存储过程.触发器. 为方便大家跟着我的笔记练习,为此提供数据库表文件给大家下载:点我下载 为了要有输出的结 ...

  3. Python3编写自动签到服务程序

    公司加班的餐补需要登录网站签到领取,有时候会忘记,于是自己用Python写了小程序来自动签到.刚开始只是做了自己用,直接写的黑框程序,后来给同事用,就打包成exe.再后来有人说要写成window服务会 ...

  4. 【汇编】MASM6.15几个简单的汇编程序

    /***************通过调用(INT 21H)表中的01h号功能号从键盘输入一个字符并回显到视频显示器上*****************/ DATAS SEGMENT ;此处输入数据段代 ...

  5. Delphi 不用标题栏移动窗体

    procedure TxxxxForm.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: I ...

  6. drf04 drf视图类

    REST framework 提供了众多的通用视图基类与扩展类,以简化视图的编写. 1.2个视图基类 1.1. APIView rest_framework.views.APIView APIView ...

  7. day37-2元类,单例模式

    目录 元类 造类的第一种形式 class做了什么事 控制元类产生的类 控制元类产生的对象 实例化类 加上元类后类的属性查找顺序 元类控制模版 单例模式 1. 使用类方法的特性 2. 使用装饰器 3. ...

  8. Python之数据结构改造

    { "appList":[ { "id" : 120, "name" : "BIGDATA", "alias& ...

  9. STM32F103 rtthread工程构建

    目录 STM32F103 工程构建 1.基本情况 2.硬件连接 3.rtthread配置 4.点灯 5. 码云上git操作 STM32F103 工程构建 1.基本情况 RAM 20K ROM 64K ...

  10. 终于等到你!微软正式上线 Windows Terminal 预览版

    前一段时间,一直在知乎.技术社区收到技术小伙伴们的终极拷问:微软Build 大会上提到的**6月中旬**要上Windows store 的 Windows Terminal 到底啥时候可以用到呀? 有 ...