hdu1627 Krypton Factor(注意后缀+dfs)
来源:互联网 发布:java 兼职 编辑:程序博客网 时间:2024/06/15 22:36
You have been employed by the organisers of a Super Krypton Factor Contest in which contestants have very high mental and physical abilities. In one section of the contest the contestants are tested on their ability to recall a sequenace of characters which has been read to them by the Quiz Master. Many of the contestants are very good at recognising patterns. Therefore, in order to add some difficulty to this test, the organisers have decided that sequences containing certain types of repeated subsequences should not be used. However, they do not wish to remove all subsequences that are repeated, since in that case no single character could be repeated. This in itself would make the problem too easy for the contestants. Instead it is decided to eliminate all sequences containing an occurrence of two adjoining identical subsequences. Sequences containing such an occurrence will be called ``easy''. Other sequences will be called ``hard''.
For example, the sequence ABACBCBAD is easy, since it contains an adjoining repetition of the subsequence CB. Other examples of easy sequences are:
BB
ABCDACABCAB
ABCDABCD
Some examples of hard sequences are:
D
DC
ABDAB
CBABCBA
For example, the sequence ABACBCBAD is easy, since it contains an adjoining repetition of the subsequence CB. Other examples of easy sequences are:
BB
ABCDACABCAB
ABCDABCD
Some examples of hard sequences are:
D
DC
ABDAB
CBABCBA
For example, with L = 3, the first 7 hard sequences are:
A
AB
ABA
ABAC
ABACA
ABACAB
ABACABA
As each sequence is potentially very long, split it into groups of four (4) characters separated by a space. If there are more than 16 such groups, please start a new line for the 17th group.
Therefore, if the integers 7 and 3 appear on an input line, the output lines produced should be
ABAC ABA
7
Input is terminated by a line containing two zeroes. Your program may assume a maximum sequence length of 80.
ABAC ABCA CBAB CABA CABC ACBA CABA28
30 30 0
ABAC ABCA CBAB CABA CABC ACBA CABA28
题目啥意思呢:
输入n,L
L表示前L个字母,如果L等于3,则用字母ABC
n表示通过一定操作的字典序,啥操作:任意的一串字符串不含两个相同的子串。
这里我们可以使用后缀来写,因为插入一个字母,只需判断插入后含该字母的子串
#include <iostream>using namespace std; const int maxn=100;char s[maxn];int n,l;int ans=0;bool check(char *s1,int len){//长度 for(int i=1;i<=len/2;i++){bool flag=0;//for(int j=len;j>=len-i+1;j--){if(s1[j]!=s1[j-i]) {flag=true;break;}} if(flag==0)return false;} return true;}void dfs(int cur){if(ans==n){for(int i=1;i<cur;i++){cout<<s[i];if(i%64==0&&i!=(cur-1)){cout<<endl;continue;}if(i%4==0&&i!=(cur-1))cout<<" ";}cout<<endl;cout<<cur-1<<endl;}if(ans>n)return; for(int i=1;i<=l;i++){char cur_c=i+'A'-1;s[cur]=cur_c;if(check(s,cur)){ans++;//cout<<"递归 "<<cur_c<<endl;dfs(cur+1);}}}int main() {while(cin>>n>>l){ans=0;if(n==0&&l==0)break;dfs(1);}return 0; }
阅读全文
0 0
- hdu1627 Krypton Factor(注意后缀+dfs)
- hdu1627 Krypton Factor(回溯法)
- UVa 129 - Krypton Factor (DFS 回溯)
- 129 - Krypton Factor(dfs回溯)
- UVa--129 Krypton Factor(DFS)
- UVA-129 Krypton Factor(dfs)
- UVa 129 - Krypton Factor(DFS+回溯)
- uva 129 Krypton Factor (DFS+巧妙的判断方法)
- Krypton Factor
- UVa129 - Krypton Factor 不错的DFS入门题
- Uva129 Krypton Factor【dfs回溯】【例题7-5】
- UVA - 129 Krypton Factor (回溯)
- UVa 129:Krypton Factor(回溯)
- 困难的串(Krypton Factor,UVa129)
- UVa-129-Krypton Factor(回溯法)
- HDU-1627-Krypton Factor
- uva 129 Krypton Factor
- [回溯]Krypton Factor UVA129
- Keil MDK生成bin文件
- pandas.read_csv——分块读取大文件
- JacK_C#_类在分数上的运用
- 数据库语句学习
- 740[Medium]:Delete and Earn
- hdu1627 Krypton Factor(注意后缀+dfs)
- MySQL学习总结4:多表操作
- Ruby on Rails基于ruby2.4.2的hello world
- css实现文本超出部分显示省略号
- 回调机制简述
- 往mysql中插入 自增id不连续(曾经的坑)
- 自定义一个具有倒角的三角形标签(RoundLabelTextView)
- 数据预处理:PCA原理推导
- 公众号使用指南