Codeforces Round #265 (Div. 2) C. No to Palindromes! 构建无回文串子
http://codeforces.com/contest/465/problem/C
给定n和m,以及一个字符串s,s不存在长度大于2的回文子串,如今要求输出一个字典比s大的字符串,且串中字母在一定范围内,而且说相同不存在长度大于2的回文子串。
直接去递归构造就可以。从最后一位開始。每次仅仅要推断是否子串中含有回文串,事实上细致想想仅仅要考虑是否存在一个字符和前两个字符中的一个同样就可以。不卡时限,裸的推断都能过
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include<set>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define clr0(x) memset(x,0,sizeof(x))
typedef long long LL;
int p,n;
char ch[1005],ans[1005];
//int fun(int low, int high, char *str, int length)
//{
// if (length == 0 || length == 1)
// return 1;
// if (str[low] != str[high])
// return 0;
// return fun(low+1, high-1, str, length-2);
//}
int fun(int low, int high, char *str, int length)
{
if (length == 0 || length == 1)
return false;
if(str[low] == str[low+1])
return true;
for(int i = low + 2;i <= high;++i){
if(str[i] == str[i-1] || str[i] == str[i-2])
return true;
}
return false;
}
bool find(int x,bool big)
{
if(x == n){
if(strcmp(ch,ans) == 0)
return false;
return true;
}
for(char i = big? 'a':ch[x];i < p+'a';++i){
ans[x] = i;
int j;
if(fun(0,x,ans,x+1)) continue;
// for(j = 0;j < x;++j)
// if(fun(j,x,ans,x-j+1))
// break;
// if(j != x) continue;
if(find(x+1,big|ans[x] > ch[x]))
return true;
}
return false;
}
int main() {
RD2(n,p);
scanf("%s",ch);
ans[n] = '\0';
if(find(0,0))
puts(ans);
else
puts("NO");
return 0;
}
版权声明:本文博主原创文章,博客,未经同意不得转载。
Codeforces Round #265 (Div. 2) C. No to Palindromes! 构建无回文串子的更多相关文章
- Codeforces Round #265 (Div. 2) C. No to Palindromes! 构造不含回文子串的串
http://codeforces.com/contest/465/problem/C 给定n和m,以及一个字符串s,s不存在长度大于2的回文子串,现在要求输出一个字典比s大的字符串,且串中字母在一定 ...
- Codeforces Round #265 (Div. 2)
http://codeforces.com/contest/465 rating+7,,简直... 感人肺腑...............蒟蒻就是蒟蒻......... 被虐瞎 a:inc ARG 题 ...
- Codeforces Round #265 (Div. 1) C. Substitutes in Number dp
题目链接: http://codeforces.com/contest/464/problem/C J. Substitutes in Number time limit per test 1 sec ...
- Codeforces Round #265 (Div. 2) E. Substitutes in Number
http://codeforces.com/contest/465/problem/E 给定一个字符串,以及n个变换操作,将一个数字变成一个字符串,可能为空串,然后最后将字符串当成一个数,取模1e9+ ...
- Codeforces Round #265 (Div. 2) D. Restore Cube 立方体判断
http://codeforces.com/contest/465/problem/D 给定8个点坐标,对于每个点来说,可以随意交换x,y,z坐标的数值.问说8个点是否可以组成立方体. 暴力枚举即可, ...
- Codeforces Round #265 (Div. 2) D. Restore Cube 立方体推断
http://codeforces.com/contest/465/problem/D 给定8个点坐标.对于每一个点来说,能够任意交换x.y,z坐标的数值. 问说8个点能否够组成立方体. 暴力枚举就可 ...
- Codeforces Round #265 (Div. 2) E
这题说的是给了数字的字符串 然后有n种的操作没次将一个数字替换成另一个字符串,求出最后形成的字符串的 数字是多大,我们可以逆向的将每个数推出来,计算出他的值和位数记住位数用10的k次方来记 1位就是1 ...
- Codeforces Round #265 (Div. 2) B. Inbox (100500)
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others ...
- Codeforces Round #265 (Div. 1)
D. World of Darkraft - 2 time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
随机推荐
- mysql计算指定的时间TPS
<pre name="code" class="sql">有朋友留言,需要监视如早晨在规定时间内9设置18分TPS,写一个10在几秒钟内TPS方法. ...
- Fire Net HDU
Fire Net Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Subm ...
- 2014年CCNU-ACM暑期集训总结
2014年CCNU-ACM暑期集训总结 那个本期待已久的暑期集训居然就这种.溜走了.让自己有点措手不及.很多其它的是对自己的疑问.自己是否能在ACM这个领域有所成就.带着这个疑问,先对这个暑假做个总结 ...
- redis client protocol 分解
在官方网站http://redis.io/topics/protocol我们必须redis通信协议做说明. 根据以下某些原因.我想解决redis client protocol: 1.足够了解通信协议 ...
- Android 深入解析光传感器(二)
光线传感器演示1 讲了一大堆的理论,那么以下的样例就来展示一下光线感应器的使用.为什么充分展现光感的用法,我这个样例写的很easy,仅仅写了使用光感必须的代码,然后用了几个textVie ...
- QtQuick桌面应用程序开发指南 4)动态管理Note对象_B 5)加强外观 6)许多其他的改进
4.2.2 Stateless(不管状态)JavaScript库 为了让开发轻松点, 使用一个JavaScript接口来和数据库交互是个好主意, 它在QML中提供了方便的方法; 在QtCreator中 ...
- 2014阿里巴巴web前实习生项目分析(1)
以下简化CSS代码: div.container{ width:500px; background-image:url(/img/sprite.png); background-repeat:no-r ...
- 百度云盘建svnserver步骤
安装tortoisesvn(略) 安装visualsvn(主server您可以使用)(略步骤)例如下面的安装文件夹后,: 注冊百度账号.进入百度云盘页面,建立目录,如mysvn. 下载百度云盘clie ...
- Oracle中REGEXP_SUBSTR及其它支持正则表达式的内置函数小结
Oracle中REGEXP_SUBSTR函数的使用说明: 题目如下:在oracle中,使用一条语句实现将'17,20,23'拆分成'17','20','23'的集合. REGEXP_SUBSTR函数格 ...
- IIS7启用静态压缩
IIS7启用压缩的操作如下图: 默认情况下IIS7是启用GZip压缩的,但是有时候我们会发现谁然启用了压缩但是一些js和css文件仍然没有被压缩,这个时候需要修改一下IIS 的配置文件: 在C:\Wi ...