http://acm.hdu.edu.cn/showproblem.php?pid=1627

给定 n 和 L 找出第n个范围在0-L之内的字符串,字符串要求没有相邻的子串是相同的。

按照格式输出。

这个题的关键在于判断字符串是否是符合要求的字符串.

枚举字符串所有子串可能的长度,然后判断即可。

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cmath>
  4. #include <vector>
  5. #include <cstring>
  6. #include <string>
  7. #include <algorithm>
  8. #include <string>
  9. #include <set>
  10. #include <functional>
  11. #include <numeric>
  12. #include <sstream>
  13. #include <stack>
  14. #include <map>
  15. #include <queue>
  16. #pragma comment(linker, "/STACK:102400000,102400000")
  17. #define CL(arr, val) memset(arr, val, sizeof(arr))
  18.  
  19. #define ll long long
  20. #define inf 0x7f7f7f7f
  21. #define lc l,m,rt<<1
  22. #define rc m + 1,r,rt<<1|1
  23. #define pi acos(-1.0)
  24.  
  25. #define L(x) (x) << 1
  26. #define R(x) (x) << 1 | 1
  27. #define MID(l, r) (l + r) >> 1
  28. #define Min(x, y) (x) < (y) ? (x) : (y)
  29. #define Max(x, y) (x) < (y) ? (y) : (x)
  30. #define E(x) (1 << (x))
  31. #define iabs(x) (x) < 0 ? -(x) : (x)
  32. #define OUT(x) printf("%I64d\n", x)
  33. #define lowbit(x) (x)&(-x)
  34. #define Read() freopen("a.txt", "r", stdin)
  35. #define Write() freopen("b.txt", "w", stdout);
  36. #define maxn 1000000000
  37. #define N 2510
  38. #define mod 1000000000
  39. using namespace std;
  40. int n,m;
  41. int a[];
  42.  
  43. void dfs(int cur)
  44. {
  45. for(int i=;i<m;i++)
  46. {
  47. a[cur]=i;
  48. bool is=;
  49. for(int j=;*j<=cur+;j++) //枚举 所有 的可能长度,
  50. {
  51. bool flag=;
  52. for(int k=;k<j;k++) //判断是否符合要求
  53. if(a[cur-k]!=a[cur-j-k]) {flag=;break;}
  54. if(!flag)
  55. {
  56. is=;
  57. break;
  58. }
  59. }
  60. if(is) continue;
  61. if(--n==)
  62. {
  63. for(int j=;j<=cur;j++)
  64. {
  65. if(j&&j%==) printf("\n");
  66. else if(j&&j%==) printf(" ");
  67. printf("%c",a[j]+'A');
  68. }
  69. printf("\n");
  70. printf("%d\n",cur+);
  71. }
  72. dfs(cur+);
  73. if(n==) return;
  74. }
  75. }
  76. int main()
  77. {
  78. //freopen("a.txt","r",stdin);
  79. while(~scanf("%d%d",&n,&m))
  80. {
  81. if(n==&&m==) break;
  82. dfs();
  83. }
  84. return ;
  85. }

hdu - 1627 Krypton Factor (dfs)的更多相关文章

  1. HDU 1627 Krypton Factor

    回溯法:避免无用判断,强化回溯代码的实现过程 题目的大意就是以字典序为准,排列字符串,但要保证一个字符串中不包含相邻的重复子串. Problem Description For example, th ...

  2. UVa 129 Krypton Factor (DFS && 回溯)

    题意 : 如果一个字符串包含两个相邻的重复子串,则称它是“容易的串”,其他串称为“困难的 串”.例如,BB.ABCDACABCAB.ABCDABCD都是容易的串,而D.DC.ABDAB. CBABCB ...

  3. UVA129 Krypton Factor 困难的串 dfs回溯【DFS】

     Krypton Factor Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  4. Krypton Factor

    Krypton Factor Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  5. UVA.129 Krypton Factor (搜索+暴力)

    UVA.129 Krypton Factor (搜索+暴力) 题意分析 搜索的策略是:优先找长串,若长串不合法,则回溯,继续找到合法串,直到找到所求合法串的编号,输出即可. 注意的地方就是合法串的判断 ...

  6. 129 - Krypton Factor

    /*UVa129 - Krypton Factor --回溯问题.看例子可知道确定该字符串是按照从左到右依次考虑每个位置,当前位置填不上所有的字符时,需要回溯. -- */ #define _CRT_ ...

  7. HDOJ(HDU).2660 Accepted Necklace (DFS)

    HDOJ(HDU).2660 Accepted Necklace (DFS) 点我挑战题目 题意分析 给出一些石头,这些石头都有自身的价值和重量.现在要求从这些石头中选K个石头,求出重量不超过W的这些 ...

  8. HDOJ(HDU).1045 Fire Net (DFS)

    HDOJ(HDU).1045 Fire Net [从零开始DFS(7)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HD ...

  9. HDOJ(HDU).1241 Oil Deposits(DFS)

    HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...

随机推荐

  1. .net主站和二级域名下实现session共享

    public class CrossDomainCookie : IHttpModule { private string m_RootDomain = string.Empty; #region I ...

  2. hihocoder编程练习赛52-1 字符串排序

    思路: 将字符串按照新的顺序映射之后再排序. 实现: #include <bits/stdc++.h> using namespace std; int main() { int n; s ...

  3. BaseAdapter的优化

    传统的 package cct.commonadapter.bean; import android.content.Context; import android.view.LayoutInflat ...

  4. SQL SERVER的数据类型

    1.SQL SERVER的数据类型 数据类弄是数据的一种属性,表示数据所表示信息的类型.任何一种计算机语言都定义了自己的数据类型.当然,不同的程序语言都具有不同的特点,所定义的数据类型的各类和名称都或 ...

  5. 最全的Java面试宝典

    一. 前言部分 从享受生活的角度上来说:“程序员并不是一种最好的职业,我认为两种人可以做程序员,第一,你不做程序员,你就没有什么工作可做,或者说是即使有可以做的工作但是你非常不愿意去做:第二,你非常痴 ...

  6. JS对json中某字段进行排序

    var data =[ { "cid":1, "name":"aaa", "price":1000 },{ " ...

  7. css 样式渲染

     1.文字过长时,自动换行

  8. col - 过滤掉输入中的反向换行符

    SYNOPSIS(总览) col [-bfx ] [ Fl l Ar num ] DESCRIPTION(描述) Col 过滤掉反向(以及半反向)换行符(LF: line feed or NL: ne ...

  9. cesium 原理 之 command拼接

    VAO VAO(Vertext Array Object),中文是顶点数组对象.之前在<Buffer>一文中,我们介绍了Cesium如何创建VBO的过程,而VAO可以简单的认为是基于VBO ...

  10. CAD参数绘制块引用对象(网页版)

    主要用到函数说明: _DMxDrawX::DrawBlockReference 绘制块引用对象.详细说明如下: 参数 说明 DOUBLE dPosX 插入点的X坐标 DOUBLE dPosY 插入点的 ...