Krypton Factor UVA
来源:互联网 发布:天龙八部手游染色数据 编辑:程序博客网 时间:2024/04/29 21:29
按照紫书当中的思路进行回溯,注意每次只用判断当前位置插入之后是否满足要求即可,具体实现见如下代码:
#include<iostream>#include<vector>#include<string>#include<set>#include<stack>#include<queue>#include<map>#include<algorithm>#include<cmath>#include<iomanip>#include<cstring>#include<sstream>#include<cstdio>#include<deque>using namespace std;int n, L,seq;vector<char> result;int dfs(){if (seq == n){for (int i = 0; i < result.size(); i++) {if (i != 0 && i % 4 == 0 && i % 64 != 0) cout << " ";else if (i != 0 && i % 64 == 0) cout << endl;cout << result[i];}cout <<endl<< result.size() << endl;return 1;}seq++;for (int i = 0; i < L; i++){result.push_back('A'+i);int length = result.size();int ok=1;for (int j = 1; j * 2 <= length; j++){bool equal = true;for (int k = 0; k < j; k++){if (result[length - 1 - k] != result[length - 1 - j - k]){equal = false;break;}}if (equal){ok = 0;break;}}if (ok){if (dfs()) return 1;}result.pop_back();}return 0;}int main(){while (cin >> n >> L){if (n == 0 && L == 0) break;result.clear();seq = 0;dfs();}return 0;}
阅读全文
0 0
- uva 129 Krypton Factor
- uva 129 - Krypton Factor
- UVa 129 Krypton Factor
- UVA - 129 Krypton Factor
- UVa-129 - Krypton Factor
- UVa - 129 - Krypton Factor
- UVA - 129 Krypton Factor
- uva 129 - Krypton Factor
- uva 129 - Krypton Factor
- UVA 129 Krypton Factor
- UVA - 129 Krypton Factor
- UVa 129 Krypton Factor
- uva 129 Krypton Factor
- UVA 129 - Krypton Factor
- uva 129 Krypton Factor
- UVa-129-Krypton Factor
- UVA-129 Krypton Factor
- 紫书章七例五 Krypton Factor UVA
- 数据类型 数据类型转换 运算符
- 面试总结之拥塞控制与流量控制
- (一)理解XAML
- MYSQL 中group by,order by用法详解及其特殊用法
- UVA
- Krypton Factor UVA
- 关键帧的边缘检测
- 远景能源电话面试总结
- UVA
- CSS中正确理解clear:both
- 1018. 锤子剪刀布 (20)
- Java集合框架
- 自定义view中控件的点击事件
- JSONP跨域请求