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! 构建无回文串子的更多相关文章

  1. Codeforces Round #265 (Div. 2) C. No to Palindromes! 构造不含回文子串的串

    http://codeforces.com/contest/465/problem/C 给定n和m,以及一个字符串s,s不存在长度大于2的回文子串,现在要求输出一个字典比s大的字符串,且串中字母在一定 ...

  2. Codeforces Round #265 (Div. 2)

    http://codeforces.com/contest/465 rating+7,,简直... 感人肺腑...............蒟蒻就是蒟蒻......... 被虐瞎 a:inc ARG 题 ...

  3. 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 ...

  4. Codeforces Round #265 (Div. 2) E. Substitutes in Number

    http://codeforces.com/contest/465/problem/E 给定一个字符串,以及n个变换操作,将一个数字变成一个字符串,可能为空串,然后最后将字符串当成一个数,取模1e9+ ...

  5. Codeforces Round #265 (Div. 2) D. Restore Cube 立方体判断

    http://codeforces.com/contest/465/problem/D 给定8个点坐标,对于每个点来说,可以随意交换x,y,z坐标的数值.问说8个点是否可以组成立方体. 暴力枚举即可, ...

  6. Codeforces Round #265 (Div. 2) D. Restore Cube 立方体推断

    http://codeforces.com/contest/465/problem/D 给定8个点坐标.对于每一个点来说,能够任意交换x.y,z坐标的数值. 问说8个点能否够组成立方体. 暴力枚举就可 ...

  7. Codeforces Round #265 (Div. 2) E

    这题说的是给了数字的字符串 然后有n种的操作没次将一个数字替换成另一个字符串,求出最后形成的字符串的 数字是多大,我们可以逆向的将每个数推出来,计算出他的值和位数记住位数用10的k次方来记 1位就是1 ...

  8. 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 ...

  9. Codeforces Round #265 (Div. 1)

    D. World of Darkraft - 2 time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

随机推荐

  1. F5当刷新页面,出现“要再次显示此页,web该浏览器,你曾经有过发送消息再次提交...点击重试&quot;,如何防止此对话框解决方案的出现,

    如何取消刷新页面弹出"重试"对话? 找了好多类似的问题都没有我想要的答案,请大家看清楚再回答. 比方说,登录过程中,成功之后转向还有一个页面success.jsp, 这时,假设刷新 ...

  2. Jenkins详细安装与构建部署使用教程(转)

    Jenkins是一个开源软件项目,旨在提供一个开放易用的软件平台,使软件的持续集成变成可能.Jenkins是基于Java开发的一种持续集成工具,用于监控持续重复的工作,功能包括:1.持续的软件版本发布 ...

  3. A WPF/MVVM Countdown Timer

    Introduction This article describes the construction of a countdown timer application written in C# ...

  4. jQuery 焦点图,图像文件js档

    jQuery 焦点图,图片文件在js文件里 演示 XML/HTML Code <div id="photo_container"></div> JavaSc ...

  5. windows下搭建Apache+Mysql+PHP开发环境

    原文:windows下搭建Apache+Mysql+PHP开发环境 要求 必备知识 熟悉基本编程环境搭建. 运行环境 windows 7(64位); Apache2.2;MySQL Server 5. ...

  6. 于win7使用虚拟磁盘隐藏文件

    于win7使用虚拟磁盘隐藏文件,我只是win7在验证.其他型号未知. 一.创建虚拟磁盘 1.右键点击"计算机"-----"管理" ------"磁盘管 ...

  7. JS于string 和 json互转对象

    一.json开启string JSON.stringify(jsonObj) 两.string开启json eval(string) 版权声明:本文博主原创文章.博客,未经同意不得转载.

  8. poj 1061 扩展欧几里德同余方程求解

    摘要写在一瞪眼. #include<iostream> using namespace std; long long exgcd(long long a,long long b,long ...

  9. Hibernate-----5、持久化对象

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaGVrZXdhbmd6aQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

  10. 2C 产品的本质是人性,2B 产品的背后是业务(转)

    本文作者李源是 BLUES 原来做 YY 语音客户端产品时候的同事,原来针对 YY 语音的游戏用户做 2C 的 PC 客户端产品和 APP,后来到某品牌手机做 2B 的后台系统.以下文章,是作者经历了 ...