标签:
不难,细心,先写框架,逐步完善即可。
#include <iostream>#include <cstdio>using namespace std;int n, L, ans[80], cnt(0), ove = false;;bool isHard(int cur) {int bor = (cur + 1) / 2;for (int i = 1; i != bor + 1; ++i) {bool ok = false;for (int j = 0; j != i ; ++j) {if (ans[cur - j] != ans[cur - i - j]) {ok = true;break;}}if (!ok) return false;if (i == bor && ok) return true;}}void dfs(int cur) {if (ove) return;if (cnt == n) {ove = true;for (int i = 0; i != cur + 1; ++i) {if (i && !(i % 4) && i != 64) printf(" ");if (i == 64) printf("\n");printf("%c", ans[i] + ‘A‘);}printf("\n%d\n", cur + 1);} else {for (int i = 0; i != L; ++i) {ans[cur + 1] = i;if (isHard(cur + 1)) {++cnt;dfs(cur + 1);}}}}int main() {while (scanf("%d%d", &n, &L) == 2 && n) {ove = false;cnt = 0;for (int i = 0; i != L; ++i) {ans[0] = i;++cnt;dfs(0);}}return 0;}
标签:
原文地址:http://www.cnblogs.com/liangyongrui/p/4678406.html