Rosalind第40题:Ordering Strings of Varying Length Lexicographically

Problem

Say that we have strings  and  with . Consider the substring . We have two cases:

  1. If , then we set  because  is shorter than  (e.g., ).
  2. Otherwise, . We define  if  and define  if  (e.g.,  because ).

Given: A permutation of at most 12 symbols defining an ordered alphabet  and a positive integer  ().

Return: All strings of length at most  formed from , ordered lexicographically. (Note: As in “Enumerating k-mers Lexicographically”, alphabet order is based on the order in which the symbols are given.)

说我们有琴弦  和  与 。考虑子串。我们有两种情况:

  1. 如果 ,然后我们设置  因为  短于  (例如, )。
  2. 除此以外, 。我们定义 如果  并定义  如果  (例如,  因为 )。

给定:最多12个符号的排列,定义一个有序字母  和一个正整数  ()。

返回:最多所有长度的字符串 由...组成 ,按字典顺序排序。(注意:与字典顺序枚举k-mers”中一样,字母顺序基于给出符号的顺序。)

Sample Dataset

D N A
3

Sample Output

D
DD
DDD
DDN
DDA
DN
DND
DNN
DNA
DA
DAD
DAN
DAA
N
ND
NDD
NDN
NDA
NN
NND
NNN
NNA
NA
NAD
NAN
NAA
A
AD
ADD
ADN
ADA
AN
AND
ANN
ANA
AA
AAD
AAN
AAA
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值