Codeforces.666A.Reberland Linguistics(DP)
\(Description\)
给定串s,其由一个基本串后加任意多个长度为2或3的后缀串构成,要求基本串长度>4且相邻后缀串不相同。在基本串任意确定的情况下,求所有可能的后缀串。
\(|s|\leq 10^4\)。
\(Solution\)
把串反过来求前缀方便些。
明显的dp,f[i][2/3]表示当前到i,上一个后缀串长度为2/3是否可行。边转移边更新答案就行了。
#include <cstdio>
#include <cstring>
#include <algorithm>
#define pc putchar
const int N=10005;
int n;
bool f[N][2]/*0:2 1:3*/,ok2[28][28],ok3[28][28][28];
char s[N];
int main()
{
scanf("%s",s+1), n=strlen(s+1);
std::reverse(s+1,s+1+n);
int tot=0; n-=5;
if(n>=2) f[2][0]=1, ++tot, ok2[s[2]-'a'][s[1]-'a']=1;
if(n>=3) f[3][1]=1, ++tot, ok3[s[3]-'a'][s[2]-'a'][s[1]-'a']=1;
for(int i=4; i<=n; ++i)
{
int a=s[i]-'a', b=s[i-1]-'a', c=s[i-2]-'a';
if(f[i-2][1]||(f[i-2][0]&&(s[i]!=s[i-2]||s[i-1]!=s[i-3])))
{
f[i][0]=1;
if(!ok2[a][b]) ++tot, ok2[a][b]=1;
}
if(f[i-3][0]||(f[i-3][1]&&(s[i]!=s[i-3]||s[i-1]!=s[i-4]||s[i-2]!=s[i-5])))//i>=6
{
f[i][1]=1;
if(!ok3[a][b][c]) ++tot, ok3[a][b][c]=1;
}
}
printf("%d\n",tot);
for(int i=0; i<27&&tot; ++i)
{
for(int j=0; j<27; ++j)
{
if(ok2[i][j]) --tot,pc(i+'a'),pc(j+'a'),pc('\n');
for(int k=0; k<27; ++k)
if(ok3[i][j][k]) --tot,pc(i+'a'),pc(j+'a'),pc(k+'a'),pc('\n');
}
}
return 0;
}
Codeforces.666A.Reberland Linguistics(DP)的更多相关文章
- CodeForces 666A Reberland Linguistics(DP)
A. Reberland Linguistics time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces 667C Reberland Linguistics 记忆化搜索
链接 Codeforces 667C Reberland Linguistics 题意 给你一个字符串,除去前5个字符串后,使剩下的串有长度为2或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 问 ...
- codeforces 667C C. Reberland Linguistics(dp)
题目链接: C. Reberland Linguistics time limit per test 1 second memory limit per test 256 megabytes inpu ...
- Codeforces Round #349 (Div. 2) C. Reberland Linguistics DP+set
C. Reberland Linguistics First-rate specialists graduate from Berland State Institute of Peace a ...
- CodeForces 667C Reberland Linguistics
$dp$. 题意中有一个词组:$in$ $a$ $row$,是连续的意思.... 因此这题只要倒着$dp$一下就可以了.$f[i][0]$表示从$i$位置往后割两个能否割,$f[i][1]$表示从$i ...
- Codeforces 667C Reberland Linguistics【DFS】
一道卡题意的题. 题目链接: http://codeforces.com/problemset/problem/667/C 题意: 一个串可以看成一个长度大于4的根,加上其后面的若干个相邻(in a ...
- 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 ...
- Codeforces Round #349 (Div. 1) A. Reberland Linguistics 动态规划
A. Reberland Linguistics 题目连接: http://www.codeforces.com/contest/666/problem/A Description First-rat ...
随机推荐
- .net MVC入门
这里面之所以没有Sql语句但是也可以对数据库进行数据操作的原因就是Entity Framework.Entity Framework有三种模式,这里用的是Models模式. 网上有太多的.net MV ...
- Linux学习6-套接字
套接字 1.什么是套接字? 套接字(socket)是一种通信机制,凭借这种机制,客户/服务器系统的开发工作既可以在本地单机上进行,也可以跨网络进行. 2.套接字应用程序是如何通过套接字来维持一个连接的 ...
- [游戏数据分析]WAU模型简介及WAU预测
声明:本博客中所采用的数据并非真实数据,会对真实数据加以变换,重在讨论游戏数据分析的思路. 这里是参考友盟的WAU模型[文章网址, 演示网址],利用某款游戏(以下称为游戏A)数据进行的分析. 作用: ...
- [BZOJ 4350]括号序列再战猪猪侠 题解(区间DP)
[BZOJ 4350]括号序列再战猪猪侠 Description 括号序列与猪猪侠又大战了起来. 众所周知,括号序列是一个只有(和)组成的序列,我们称一个括号 序列S合法,当且仅当: 1.( )是一个 ...
- 重启虚拟目录或站点,不重启iis
更改站点或虚拟目录的.net Framework 版本会导致重启整个iis服务,所以需要单独重启某个站点或虚拟目录 首先右键点击网站-所有任务-将配置保存到一个文件,从文件中查找到 Location ...
- 使用Cobbler批量部署Linux和Windows:Cobbler服务端部署(一)
本文记录了我使用Cobbler批量安装部署Linux和Windows系统的过程,文章主要分为三部分:Cobbler服务端的安装配置.Linux发行版CentOS和Ubuntu的自动安装部署.Windo ...
- Oracle 数据库和监听器开机自启动两种实现方法
数据库和监听器开机自启动 编辑oratab文件: 修改:orcl:/u01/app/oracle/product/11.2.0/db_1:N orcl:/u01/app/or ...
- Ibatis.Net 输出SQL语句学习(七)
一.IBatis.net输出SQL语句 输出IBatis.net生成的SQL语句,能够方便调试. 在MapperHelper类中添加GetSql方法: /// <summary> /// ...
- 测试开发之前端——No3.HTML5中的标准属性
HTML5的标准属性 属性 值 描述 accesskey character 规定访问元素的键盘快捷键 class classname 规定元素的类名(用于规定样式表中的类). contentedit ...
- 使用html+css+js实现弹球游戏
使用html+css+js实现弹球游戏 效果图: 代码如下,复制即可使用: <!doctype html> <head> <style type="text/c ...