UVA 129 困难的串Krypton Factor (回溯法)
来源:互联网 发布:建筑外观上色软件 编辑:程序博客网 时间:2024/05/22 08:14
#include<cstdio>const int maxn=80+2;int S[maxn];int n,L,count;void print(int cur){int flag=1;for(int i=0;i<cur;i++){if(i%4==0 && i>0){if(i%64==0 && i>0)printf("\n");else printf(" ");}printf("%c",S[i]+'A'); }printf("\n%d\n",cur);}int dfs(int cur){if(count++==n){ print(cur); //打印目标字符串 return 0; //返回值为0,则表示找到目标串 }for(int i=0;i<L;i++){ //尝试前L个字母 S[cur]=i;int ok=1;for(int len=1;len<=(cur+1)/2;len++){int equal=1;for(int j=0;j<len;j++){if(S[cur-j]!=S[cur-j-len]){equal=0;break;} //检查前一半是否等于后一半 }if(equal){ok=0;break;}} if(ok){if(!dfs(cur+1))return 0;} //递归搜索,如果已经找到解,则直接退出 }return 1;}int main(){while(scanf("%d%d",&n,&L)==2){if(n==0 && L==0)break;count=0; //表示第n个困难的串 dfs(0);}return 0;}
1 0
- UVA 129 困难的串Krypton Factor (回溯法)
- 困难的串(Krypton Factor,UVa 129)
- Uva 129 Krypton Factor(困难的串)
- 困难的串(Krypton Factor,UVa 129)
- UVA-129 Krypton Factor 困难的串
- 困难的串(Krypton Factor,UVa 129)
- UVa-129-Krypton Factor(回溯法)
- 例题7-5 UVA 129 Krypton Factor (困难的串,搜索)
- 例题7-5 困难的串(Krypton Factor, UVa 129)
- UVa 129 Krypton Factor (回溯好题)
- UVA - 129 Krypton Factor (回溯)
- UVA - 129 Krypton Factor 回溯+剪枝
- UVa 129 - Krypton Factor (DFS 回溯)
- UVa 129:Krypton Factor(回溯)
- 困难的串(Krypton Factor,UVa129)
- uva 129 Krypton Factor
- uva 129 - Krypton Factor
- UVa 129 Krypton Factor
- listview实现的tree树结构
- Doc-Instroduction
- java学习记录----面向对象(四)
- 响应式Web设计
- 使用ContentProvise获取APP中的数据
- UVA 129 困难的串Krypton Factor (回溯法)
- Linux中常用操作命令
- 二分查找
- Subtree with Maximum Average
- AngularJS实现原理
- java中的线程执行器总结!
- java读取properties文件内容
- *广播*
- Windows 下 Git(Tortoise)客户端使用