A. Reberland Linguistics

题目连接:

http://www.codeforces.com/contest/666/problem/A

Description

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.

Sample Input

abacabaca

Sample Output

3
aca
ba
ca

Hint

题意

给一个字符串,然后你你需要切一个长度至少为5的前缀下来,然后剩下的都得切成是长度为2或者3的字符串

你需要连续的切出来的字符串都不一样,问你能够切出多少不同的块

题解:

前面那个直接n-5就好了,就把前缀切下来了

然后考虑dp,dp[i][0]表示第i个位置,切下长度为2的可不可行

dp[i][1]表示第i个位置,切下长度为3的可不可行

dp[i][0] = dp[i-2][1] || (s[i]!=s[i-2]||s[i-1]!=s[i-3])&&dp[i-2][0]

dp[i][1]这个转移同理

然后莽一波

代码

#include<bits/stdc++.h>
using namespace std;typedef long long ll;
const int maxn = 1e4+6;
char str[maxn];
int dp[maxn][2];
int n;
vector<string>ans;
int main()
{scanf("%s",str);n=strlen(str);reverse(str,str+n);for(int i=1;i<n-5;i++){if(i==1){string s1="";s1+=str[i];s1+=str[i-1];ans.push_back(s1);dp[i][0]=1;}if(i==2){string s1="";s1+=str[i];s1+=str[i-1];s1+=str[i-2];ans.push_back(s1);dp[i][1]=1;}if(i-3>=0&&(str[i]!=str[i-2]||str[i-1]!=str[i-3])&&dp[i-2][0]==1){string s1="";s1+=str[i];s1+=str[i-1];ans.push_back(s1);dp[i][0]=1;}if(i-2>=0&&dp[i-2][1]==1){string s1="";s1+=str[i];s1+=str[i-1];ans.push_back(s1);dp[i][0]=1;}if(i-5>=0&&(str[i]!=str[i-3]||str[i-1]!=str[i-4]||str[i-2]!=str[i-5])&&dp[i-3][1]==1){string s1="";s1+=str[i];s1+=str[i-1];s1+=str[i-2];ans.push_back(s1);dp[i][1]=1;}if(i-3>=0&&dp[i-3][0]==1){string s1="";s1+=str[i];s1+=str[i-1];s1+=str[i-2];ans.push_back(s1);dp[i][1]=1;}}sort(ans.begin(),ans.end());ans.erase(unique(ans.begin(),ans.end()),ans.end());cout<<ans.size()<<endl;for(int i=0;i<ans.size();i++)cout<<ans[i]<<endl;
}

转载于:https://www.cnblogs.com/qscqesze/p/5448085.html

Codeforces Round #349 (Div. 1) A. Reberland Linguistics 动态规划相关推荐

  1. Codeforces Round #247 (Div. 2)C. k-Tree(动态规划)

    传送门 Description Quite recently a creative student Lesha had a lecture on trees. After the lecture Le ...

  2. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  3. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  4. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...

  5. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

  6. Codeforces Round #712 Div.2(A ~ F) 超高质量题解(每日训练 Day.15 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #712 Div.2(A ~ F) 题解 比赛链接:https:// ...

  7. Codeforces Round #701 (Div. 2) A ~ F ,6题全,超高质量良心题解【每日亿题】2021/2/13

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A - Add and Divide B - Replace and Keep Sorted C ...

  8. Codeforces Round #700 (Div. 2) D2 Painting the Array II(最通俗易懂的贪心策略讲解)看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 整场比赛的A ~ E 6题全,全部题目超高质量题解链接: Codeforces Round #700 ...

  9. Codeforces Round #699 (Div. 2) F - AB Tree(贪心、树上DP)超级清晰,良心题解,看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #699 (Div. 2) F - AB Tree Problem ...

最新文章

  1. iOS开发 关于启动页和停留时间的设置
  2. c# 读取excel的一系列问题
  3. 判断字符串格式_Blind_pwn之格式化字符串
  4. CSS 中的各种居中 (水平、垂直)
  5. FORM级别和数据库级别的Trace
  6. java 24种设计模式
  7. java p2p实例_java文件p2p传输
  8. 设计模式之依赖倒置原则
  9. MySql 集群/主从
  10. 使用递归方式进行二叉树的前中后序遍历
  11. 基于MQTT协议的WZ指令开发
  12. 在excel中如何筛选重复数据_Excel重复数据不会筛选?方法其实很简单!
  13. xp oracle10g安装图解,虚拟机xp系统中Oracle 10g的安装
  14. 微信小程序云开发增加定时任务
  15. win8计算机无法安装打印机驱动程序,电脑打印机无法安装驱动怎么办?如何安装驱动?...
  16. 软件著作权登记证书可以加分落户评职称评人才,不少大学不少地方把软著列入加分项,办理软件著作权需要什么流程?
  17. 练习:selenium 爬取京东的电脑商品100页的数据并保存到csv文件中
  18. 数据库读写分离的理解
  19. Integrated Data Network (IDN) and Thomson Reuters Elektron
  20. 360签名工具 linux,360apk签名工具-官方版-360apk签名工具(qihoo360apksigner)1.0官方版-独木成林...

热门文章

  1. iPhone开发进阶(9)--- 用SQLite管理数据库
  2. 不用写语句的轻量级orm_为什么说sqltoy-orm远比mybatis强大
  3. 如何在电脑上创建python_python怎么创建类Python中的除法
  4. 能打开java文件_用java打开一个本地文件
  5. select weui 动态加载数据_weui中的picker使用js进行动态绑定数据问题
  6. mysql怎么加全局锁_MySQL锁机制/管理(并发锁,行锁,表锁,预加锁,全局锁等等)
  7. Spyder导入已有文件夹
  8. python opencv教程rtsp server_Python多进程opencv调用rtsp视频流
  9. im即时通讯源码_IM消息ID技术专题(六):深度解密滴滴的高性能ID生成器(Tinyid)
  10. 使用批处理复制并以时间规则重命名文件