给定n和m,以及一个字符串s,s不存在长度大于2的回文子串,现在要求 输出一个字典比s大的字符串,且串中字母在一定范围内,并且说同样不存在长度大于2的回文子串。
直接去递归构造即可,从最后一位开始,每次只要判断是否子串中含有回文串,其实仔细想想只要考虑是否存在一个字符和前两个字符中的一个相同即可。不卡时限,裸的判断都能过
#include #include #include #include #include #include #include #include #include #include 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 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;}
查看更多关于CodeforcesRound#265(Div.2)C.NotoPalindromes!构造不含回文的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did105995