uva 129 回溯
来源:互联网 发布:js window事件绑定 编辑:程序博客网 时间:2024/05/17 08:48
#include <bits/stdc++.h>using namespace std;int n, k, cnt, S[100000], L;int dfs(int cur){if (cnt++ == n){for (int i = 0; i < cur; i++){cout << char('A' + S[i]);if ((i + 1) % 64 == 0 && i != cur - 1) cout << endl;else if ((i + 1) % 4 == 0 && i != cur - 1) cout << " ";}cout << endl;cout << cur << endl;return 0;}else for (int i = 0; i < L; i++){S[cur] = i;int ok = 1;for (int j = 1; j * 2 <= cur + 1; j++){bool equal = 1;for (int k = 0; k < j; k++)if (S[cur - k] != S[cur - k - j]){equal = 0; break;}if (equal) {ok = 0; break;}}if (ok) if (!dfs(cur + 1)) return 0;}return 1;}int main(int argc, char const *argv[]){while (cin >> n >> L){if (n == 0 && L == 0) break;cnt = 0;memset(S, 0, sizeof(S));dfs(0);}return 0;}
0 0
- uva 129 回溯
- UVA回溯
- UVa 129 Krypton Factor (回溯好题)
- UVA - 129 Krypton Factor (回溯)
- UVA - 129 Krypton Factor 回溯+剪枝
- UVa 129 - Krypton Factor (DFS 回溯)
- UVa 129:Krypton Factor(回溯)
- uva 129 Kryptopn Factor 暴力回溯
- UVa-129-Krypton Factor(回溯法)
- UVa 301 - Transportation 回溯
- ( 回溯 )uva 301 - Transportation
- Transportation-301uva 回溯
- Transportation uva+递归+回溯
- Stamps uva+回溯
- Bandwidth +uva +回溯
- Graph Coloring +uva+回溯
- uva 110(回溯)
- uva 639(回溯)
- 第三周周一 数据库操作
- iOS之TableView分组目录(快速索引)的使用
- hdu 1856 More is better(并查集)
- 跳转到指定位置
- gst xvimagesink插件不能正常生成
- uva 129 回溯
- OpenGL4.3如何管理buffer中的数据的
- 第六章
- 快速掌握 Android Studio 中 Gradle 的使用方法
- 前端开发响应式设计之媒体查询(bootstrap)
- Verilog实现任意分频和占空比
- 日常笔记
- JQUERY使用AJAX
- codeforces 476c Dreamoon and Sums