跳到正文

题解

题解 AT5807 【String Equivalence】

gyh20约 1 分钟
原文
文章信息与版本

文章信息

收录
2026年6月14日
更新
2026年6月14日
篇幅
约 1 分钟

版本

  1. v1当前

可以发现,第一个字符必须是 a\text a。

然后,之后每一个字符不能大于之前出现的字符 +1+1。

可以使用反证法,如果大于最大值 +1+1 那么可以用最大值代替。

综上,直接 dfs 一次得出答案即可。

C++
#include<bits/stdc++.h>
#define re register
using namespace std;
inline int read(){
	re int t=0;
	re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0'){
		t=(t<<3)+(t<<1)+v-48;
		v=getchar();
	}
	return t;
}
long long a;
char s[12];
inline void dfs(re int x,re char c){
	if(x==a+1){
		printf("%s\n",s+1);
		return;
	}
	for(re int i='a';i<=min(c,'z');++i){
		s[x]=i;
		if(i!=c)dfs(x+1,c);
		else dfs(x+1,c+1);
	}
}
int main(){
	a=read();
	dfs(1,'a');
}

原文