题意
一个字符串是非回文的,当且仅当,他只由前p个小写字母构成,而且他不包含长度大于等于2的回文子串。
给出长度为n的非回文串s。请找出字典序比s大的,而且字典序要最小的长度为n的非回文。
一开始想了一个做法 贪心的去改一个字符 用manacher看是不是回文 改成功就一定行
时间复杂度 1000261000
25组数据过了19组
但是其实是fake的 因为你想
4 4
abcd
我这个做法会输出dbcd
但答案其实是 abda
我们考虑一下 怎么样才能非回文呢
我们从 1位置开始dfs
那么左边的所有串一定是非回文
新加入的串不和左边所有串形成回文
就是不能形成偶数回文 和奇数回文
也就是 arr[i]!=arr[i-1] 和 arr[i]!=arr[i-2]
dfs时间复杂度是 玄学~~
AC代码
/*
if you can't see the repay
Why not just work step by step
rubbish is relaxed
to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod = (int)1e9+7;
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){
int ans=1;while(b){
if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){
return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d)