Krypton Factor UVA
来源:互联网 发布:2016淘宝主图尺寸大小 编辑:程序博客网 时间:2024/05/17 05:08
题目链接
枚举+剪枝=回溯
解题思路:首先要暴力出结果,然后在每个位置合法做判断,本题中里判断字符串是否是困难串,也就是找出所有偶数串,判断是否含有重复,在递归判断中不需要找出所有子串,只需要判断当前位置作为后缀结束,一次遍历1~cur+1/2即可。
C++代码
#include<bits/stdc++.h>using namespace std;const int maxn=1000;int A[maxn],n,L,ans;int dfs(int cur){ if(ans++==n){ for(int i=0;i<cur;i++){ if(i&&i%(4*16)==0) cout<<endl; else if(i&&i%4==0) cout<<" "; printf("%c",A[i]+'A'); } cout<<endl<<cur<<endl; return 1; } for(int i=0;i<L;i++){ int ok=1; A[cur]=i; for(int j=1;j*2<=cur+1;j++){ int equal=1; for(int k=0;k<j;k++) if(A[cur-k]!=A[cur-k-j]){equal=0;break;} if(equal){ok=0;break;} } if(ok) if(dfs(cur+1)) return 1; } return 0;}int main(){ while(memset(A,0,sizeof(A)),ans=0,cin>>n>>L&&n&&L) dfs(0); 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
- Caffe学习系列(14):初识数据可视化
- Java web项目01 停车管理系统实现用户查询功能(三)
- javax.jdo.JDOFatalDataStoreException: Failed to create database 'metastore_db', see the next excepti
- 时间序列(一)时间序列的生成
- QMUI Android UI dialog的方法介绍
- Krypton Factor UVA
- ThreadLocal的原理
- “安全协议自动验证技术服务与工具开发”之LTE
- 使用RedisTemplate访问Redis数据结构
- C++之返回数组指针
- Android Preference置灰显示
- 漫画:高并发下的HashMap引起的链表死循环原因分析
- iframe-父子-兄弟页面相互传值(jq和js两种方法)
- 百度物流API实例