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. [转]Qt 智能指针学习

    从内存泄露开始? 很简单的入门程序,应该比较熟悉吧 ^_^ #include <QApplication> #include <QLabel> int main(int arg ...

  2. ROM签名脚本[原创]

    下面的代码是bash脚本来的.需要保存为*.sh后序. # !/bin/bash #usage: signapk.sh [-hs] [zipfile-unsigned | update.zip] #A ...

  3. 特征选择(三)-K-L变换

    上一讲说到,各个特征(各个分量)对分类来说,其重要性当然是不同的. 舍去不重要的分量,这就是降维. 聚类变换觉得:重要的分量就是能让变换后类内距离小的分量. 类内距离小,意味着抱团抱得紧. 可是,抱团 ...

  4. JSP-简单的练习省略显示长字符串

    <%@ page contentType="text/html; charset=gb2312" %> <!-- JSP指令标签 --> <%@ pa ...

  5. C++ Primer注意事项11_运算符重载_算术/关系运算符_下标运算符

    1.算术/关系运算符 平时,定义成非成员函数以同意左右側运算对象进行转换.由于这些运算符一般不须要改变运算对象的状态,所以形參都是常量的引用. 以"+"号运算符为例: Person ...

  6. Reveal:分析iOS UI该武器

    Reveal是分析iOS应用UI的利器: Reveal可以在执行时调试和改动iOS应用程序.它能连接到应用程序,并同意开发人员编辑各种用户界面參数.这反过来会马上反应在程序的UI上.就像用FireBu ...

  7. CentOS7下一个mysql安装

    CentOS7安装MySQL --下载mysql http://mirrors.sohu.com/mysql/MySQL-5.6/ http://mirrors.sohu.com/mysql/MySQ ...

  8. Directx11学习笔记【四】 封装一个简单的Dx11DemoBase

    根据前面两个笔记的内容,我们来封装一个简单的基类,方便以后的使用. 代码和前面类似,没有什么新的内容,直接看代码吧(由于代码上次都注释了,这次代码就没怎么写注释o(╯□╰)o) Dx11DemoBas ...

  9. Poj3414广泛搜索

    <span style="color:#330099;">/* D - D Time Limit:1000MS Memory Limit:65536KB 64bit I ...

  10. lintcode 1: Data Stream Median

    Data Stream Median Numbers keep coming, return the median of numbers at every time a new number adde ...