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 ...
随机推荐
- Windows的DOS命令基础
Windows的DOS命令基础 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 1.dir: 查看当前路径下的目录(directory)详细信息 . 详细信息: a>.dir ...
- SpringMVC关于ajax提交400错误(后台获取为null)
400错误有三种情况 1:请求的数据量过大,不过这种情况一般很少见. 2:请求的data参数有误,确保每一个参数都能请求到. 注释:之前小白出现400错误,后台获取参数为null是因为第三种情况,经过 ...
- poj 1776 Task Sequences
http://poj.org/problem?id=1776 题意: 有一个机器要完成N个作业, 给你一个N*N的矩阵, M[i][j]=1,表示完成第i个作业后不用重启机器,继续去完成第j个作业 M ...
- eclipse 下编译c++
下载jdk 下载eclipse for c++ 版本 下载mingw ps:show project types... 这个选项不要打钩
- 转自知乎大神----JS 的 new 到底是干什么的?
大部分讲 new 的文章会从面向对象的思路讲起,但是我始终认为,在解释一个事物的时候,不应该引入另一个更复杂的事物. 今天我从「省代码」的角度来讲 new. --------------------- ...
- Jquery教你写一个简单的轮播.
这个我表示写的不咋地-_-//,但是胜在简单,可优化性不错. 实际上我本来想写个复杂点的结构的,但是最近忙成狗了!!!!所以大家就讲究着看吧 HTML结构 <div class="ba ...
- Java反射--基于ParameterizedType实现泛型类,参数化类型
一.引子: 项目中使用Gson的反序列化将json转化成具体的对象,具体方法是: package com.google.gson;下的反序列化方法 public <T> T fromJso ...
- 【API】NetUserEnum-获取系统所有账户名称
1 说明 该NetUserEnum函数检索服务器上所有用户帐户的信息. 函数原型: NET_API_STATUS NetUserEnum( _In_ LPCWSTR servername, _In_ ...
- 【技术知识】恶意PDF文件分析-PDFdump的问题
1.提醒 百度分析恶意PDF文件,很多都是推荐PDFdump.在某次沙箱产品分析出疑似高级威胁的PDF样本后,我使用PDFdump查看ShellCode的加密数据,分析后并没有找到相关的ShellCo ...
- BAT修改文本内容
@echo off (for /f "delims=" %%a in (文件名) do ( set "str=%%a" setlocal enabledelay ...