uva 129 Krypton Factor
来源:互联网 发布:风暴大陆升阶数据 编辑:程序博客网 时间:2024/06/07 23:01
题目:Krypton Factor
题意:困难的串只没有量个相同的子串相邻。找出第n个由前L个字母构成的困难的串。
思路:dfs。注意输出格式。
代码:
#include<iostream>#include<cstdio>#include<cstring>#include<vector>using namespace std;int n,m;vector<int> vec;vector<string> a;bool judge() {for(int i=1; i<=vec.size()/2; i++) {for(int j=1; j<=i; j++) {if(vec[vec.size()-i+j-1]!=vec[vec.size()-2*i+j-1]) goto END;}return false;END:;}return true;}bool dfs(int x) {string y;for(int i=0; i<vec.size(); i++) {y+=(vec[i]-1+'A');}if(judge()) {a.push_back(y);if(a.size()==n+1) return true;} else {return false;}for(int i=1; i<=m; i++) {vec.push_back(i);if(dfs(x+1)) return true;vec.pop_back();}return false;}int main() {while(scanf("%d%d",&n,&m)==2&&n!=0&&m!=0) {vec.clear(),a.clear();dfs(1);string x=a[n];for(int i=0;i<x.size();i++){if(i!=0&&i%64==0) cout<<endl;else if(i!=0&&i%4==0) cout<<' ';cout<<x[i];}cout<<endl;cout<<x.size()<<endl;}return 0;}
阅读全文
3 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
- UVA 129 Krypton Factor
- 最小生成树Prim算法学习
- 浅谈PHP中的数组和JS中的数组
- 转 gdb参数及命令详解 (已整理) core dump调试
- JDBC相关(二):数据库连接池技术原理,使用详解和常见的数据库连接池
- 解析分享SDK怎样传图片数据给分享平台
- uva 129 Krypton Factor
- 高德地图集成
- 安卓oracle数据库连接
- 一步一步制作yaffs/yaffs2根文件系统(二)---安装BusyBox,构造/bin、/sbin、/usr、linuxrc
- J
- JAVA企业面试题精选 Servlet和JSP 41-48
- hadoop集群普通用户安装时,jps命令运行报错
- 乘坐公交(贪心算法)
- OpenJudge百炼-2737-大整数除法-C语言-高精度计算