← RoseCode

ROSECODE 228

F-sequences

Philippe_57721 · Programming ·

Given two sequences X[1]...X[n] and Y[1]...Y[m] (n ≤ m), we say that the former is a subsequence of the latter if there if a sequence 1 ≤ i[1] < i[2] ... < i[n] ≤ m such as X[j] = Y[i[j]] for all 1 ≤ j ≤ n

E.g: 'PAIN' is a subsequence of 'DIOPHANTINE'

We say a sequence S[1]...S[n] is a F-sequence if no sequence S[i]...S[2*i] (2*i ≤ n) is a subsequence of any sequence S[j]...S[2*j] (i < j and 2*j ≤ n)

What is the length of longest F-sequence over the alphabet {'A','B'}?
Find the 1st F-sequence in lexicographic order over the alphabet {'A','B','C'} with length 80.

Hint:Here an example of a F-sequence of length 40:
AACBABBBBBABBCCCCCCCCCBBBBBBBBBBBBBBBBBA

Answer format: count,sequence

[My timing: < 100ms]