参考代码:
#include <cstdio> #include <cstdlib> using namespace std; const char M[] = " abcdefghijklmnopqrstuvwxyz"; int s, t, w, cnt; char p[30]; bool vis[30]; void dfs(int x) { if (x == w + s) { if (cnt) puts(p + s); if (++cnt == 6) exit(0); return ; } for (int i = s; i <= t; ++i) { if (cnt == 0) i = p[x] - 'a' + 1; if (!vis[i] && M[i] > p[x-1] && i <= t - w + 1 + x - s) { vis[i] = true; p[x] = M[i]; dfs(x + 1); vis[i] = false; } } } int main() { scanf("%d%d%d", &s, &t, &w); scanf("%s", p + s); dfs(s); return 0; }
0.0分
1 人评分