紫书章七例五 Krypton Factor UVA - 129(dfs)判断一个字符串中是否包含两个相邻子串
2017-03-20 19:44
507 查看
题意是:给你n,L(L表示所用的字符个数(从A开始),n表示第n个困难的串)
字典序比较小,意思是两个字符串相比,一直到相等的那个字符,哪个小,哪个字典序就小。
如
A
B
AB
字典序从小到大的排序为 A AB B
字典序比较小,意思是两个字符串相比,一直到相等的那个字符,哪个小,哪个字典序就小。
如
A
B
AB
字典序从小到大的排序为 A AB B
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <queue> using namespace std; int n,L;int s[100]; int cnt=0; int dfs(int cur) { if(cnt++==n){//因为是第n个 for(int i=0;i<cur;i++) {printf("%c",s[i]+'A');if((i+1)%4==0&&(i+1)!=16*4&&i!=cur-1) printf(" ");if((i+1)==16*4&&cur>16*4)printf("\n");} printf("\n"); printf("%d\n",cur); return 0; } else for(int i=0;i<L;i++){//panduan s[cur]=i;int ok=1; for(int j=1;j*2<=cur+1;j++){ int e=1; for(int k=0;k<j;k++) if(s[cur-j-k]!=s[cur-k]){e=0;break;} if(e) {ok=0;break;} } if(ok) if(!dfs(cur+1)) return 0; } return 1; } int main() { while(scanf("%d %d",&n,&L)!=EOF&&n+L) { memset(s,0,sizeof(s)); cnt=0; int k=dfs(0); } return 0; }
相关文章推荐
- 紫书章七例五 Krypton Factor UVA - 129(dfs)判断一个字符串中是否包含两个相邻子串
- 紫书章七例五 Krypton Factor UVA - 129(dfs)判断一个字符串中是否包含两个相邻子串
- 紫书章七例五 Krypton Factor UVA - 129(dfs)判断一个字符串中是否包含两个相邻子串
- 紫书章七例五 Krypton Factor UVA - 129(dfs)判断一个字符串中是否包含两个相邻子串
- 紫书章七例五 Krypton Factor UVA - 129(dfs)判断一个字符串中是否包含两个相邻子串
- 紫书章七例五 Krypton Factor UVA - 129(dfs)判断一个字符串中是否包含两个相邻子串
- 紫书章七例五 Krypton Factor UVA - 129(dfs)判断一个字符串中是否包含两个相邻子串
- 2015华为校招模拟题-判断一个数字中是否包含两个相同的子串
- 华为机试题:判断一个数字中是否包含两个相同的子串
- Python判断一个字符串是否包含子串的几种方法
- Python实现判断一个字符串是否包含子串的方法总结
- Python--判断一个字符串是否包含某子串的几种方法
- Python判断一个字符串是否包含子串的几种方法
- mysql判断一个字符串是否包含某子串 【转】
- mysql判断一个字符串是否包含某子串
- 判断一个数字中是否包含两个相同的子串
- 判断一个数字中是否包含两个相同的子串
- mysql判断一个字符串是否包含某子串
- mysql判断一个字符串是否包含某子串 【转】
- mysql判断一个字符串是否包含某子串【转】