CodeForces 667C Reberland Linguistics
$dp$。
题意中有一个词组:$in$ $a$ $row$,是连续的意思....
因此这题只要倒着$dp$一下就可以了。$f[i][0]$表示从$i$位置往后割两个能否割,$f[i][1]$表示从$i$位置往后割三个能否割。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c=getchar(); x=;
while(!isdigit(c)) c=getchar();
while(isdigit(c)) {x=x*+c-''; c=getchar();}
} const int maxn=;
char s[maxn];
int len,f[maxn][];
vector<string>ans;
map<string,bool>d; int main()
{
memset(s,,sizeof s);
scanf("%s",s); len=strlen(s);
f[len][]=f[len][]=;
for(int i=len-;i>;i--)
{
if(len-i>=)
{
if(f[i+][]==)
{
char t[]; memset(t,,sizeof t);
t[]=s[i]; t[]=s[i+]; f[i][]=;
if(d[t]==) ans.push_back(t),d[t]=;
}
else if(f[i+][]==)
{
char t[],g[]; memset(t,,sizeof t); memset(g,,sizeof g);
t[]=s[i]; t[]=s[i+]; g[]=s[i+]; g[]=s[i+]; if(strcmp(t,g)==) continue;
f[i][]=;
if(d[t]==) ans.push_back(t),d[t]=;
}
}
if(len-i>=)
{
if(f[i+][]==)
{
char t[]; memset(t,,sizeof t);
t[]=s[i]; t[]=s[i+]; t[]=s[i+]; f[i][]=;
if(d[t]==) ans.push_back(t),d[t]=;
} else if(f[i+][]==)
{
char t[],g[]; memset(t,,sizeof t); memset(g,,sizeof g);
t[]=s[i]; t[]=s[i+]; t[]=s[i+];
g[]=s[i+]; g[]=s[i+]; g[]=s[i+]; if(strcmp(t,g)==) continue;
f[i][]=;
if(d[t]==) ans.push_back(t),d[t]=;
}
}
}
sort(ans.begin(),ans.end());
printf("%d\n",ans.size());
for(int i=;i<ans.size();i++) cout<<ans[i]<<endl;
return ;
}
CodeForces 667C Reberland Linguistics的更多相关文章
- Codeforces 667C Reberland Linguistics 记忆化搜索
链接 Codeforces 667C Reberland Linguistics 题意 给你一个字符串,除去前5个字符串后,使剩下的串有长度为2或3的词根组成,相邻的词根不能重复.找到所有的词根 思路 ...
- Codeforces 667C Reberland Linguistics【DFS】
一道卡题意的题. 题目链接: http://codeforces.com/problemset/problem/667/C 题意: 一个串可以看成一个长度大于4的根,加上其后面的若干个相邻(in a ...
- CodeForces 666A Reberland Linguistics(DP)
A. Reberland Linguistics time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces.666A.Reberland Linguistics(DP)
题目链接 \(Description\) 给定串s,其由一个基本串后加任意多个长度为2或3的后缀串构成,要求基本串长度>4且相邻后缀串不相同.在基本串任意确定的情况下,求所有可能的后缀串. \( ...
- 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. 1) A. Reberland Linguistics 动态规划
A. Reberland Linguistics 题目连接: http://www.codeforces.com/contest/666/problem/A Description First-rat ...
- 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 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. 2) C. Reberland Linguistics DP+set
C. Reberland Linguistics First-rate specialists graduate from Berland State Institute of Peace a ...
随机推荐
- Web API中使用Dependency Resolver
Web API中使用Dependency Resolver 前言 阅读本文之前,您也可以到Asp.Net Web API 2 系列导航进行查看 http://www.cnblogs.com/aehyo ...
- Stream使用教程
现在,计算机CPU运行速度的快速发展已经远远超过了内存的访问速度.越来越多的程序性能被内存带宽所限制,而不是计算机的CPU运行速率. Stream benchmark是一个简单的合成基准测试程序,衡量 ...
- ASP.NET MVC 用户登录Login
ASP.NET MVC 用户登录Login一.先来看个框架例子:(这个是网上收集到的) 第一步:创建一个类库ClassLibrary831. 第二步:编写一个类实现IHttpM ...
- Combo模糊匹配中文问题
茗洋Easy UI 1.3.2 部分问题解决系列专题[Combo模糊匹配中文问题 修复] 本次给大家带来的EasyUI的我研究拓展的新特性 我使用的是 EasyUI 1.3.2版本的,项目是ASP. ...
- iOS 7 beta4 体验
iOS 7 beta4终于来了,安装后感觉稳定了不少.下面列几点我个人感受比较深得地方. 1.锁屏界面有滑动方向箭头了,而且“滑动来解锁”几个字也有动态颜色变化,让人不再迷惑该往那边滑动了. 2.通知 ...
- thrift之默认传输类TTransportDefaults和虚拟传输类TVirtualTransport
默认传输类TTransportDefaults提供了抽象类TTransport的默认实现,实现了非虚拟的方法(*_virt) read(), readAll(), write(),borrow() a ...
- OpenCV 4 Python高级配置—安装setuptools,matplotlib,six,dateutil,pyparsing 完整过程
Matplotib 是python 的一个绘图库,里头有各种各样的绘图方法,可以用Matplotib 显示图像,放大图像,保存图像等等,对于OpenCV处理图像具有非常大的帮助.但是,安装Matplo ...
- jQuery.fn.attr与jQuery.fn.prop
jQuery.fn.attr与jQuery.fn.prop jQuery.fn.attr.jQuery.fn.prop的区别 假设页面有下面这么个标签,$('#ddd').attr('nick').$ ...
- 关于Symfony2+nginx搭建过程总结
关于Symfony2+nginx搭建过程总结 最近在试着用nginx+symfony搭建公司的网站,由于nginx不支持pathinfo模式,所以必须修改nginx(我使用的是nginx1.5.1)的 ...
- Microsoft2013校园招聘笔试题
Microsoft2013校园招聘笔试题 继续求拍砖!!!! 1. You are managing the database of a book publichser, you currently ...