给定n,你可以制作多少个长度为n且只有{1,2,3}字母的字符串

时间:2015-08-27 00:22:59

标签: string math recurrence

...如果字符串中没有任何地方存在长度为3的子字符串,其中所有3个数字都存在?

换句话说,存在多少个字符串,使得以下都不是:“123”,“132”,“213”,“231”,“312”或“321”是子串?

我偶然发现了这样的问题并试图弄清楚复发,但我的复发是不正确的(我将其在代码中与强力程序进行比较)。

我现在的复发是:

f(n) = 3f(n - 1) - 6f(n - 3)

我们知道f(n)= 3f(n - 1)给出了所有可能的字符串 我们也知道有6种方法我们不想考虑:

123 concatenated with all the ways to make f(n-3)
132 concatenated with all the ways to make f(n-3)
213 concatenated with all the ways to make f(n-3)
231 concatenated with all the ways to make f(n-3)
312 concatenated with all the ways to make f(n-3)
321 concatenated with all the ways to make f(n-3)

我在这里缺少一些见解吗?这在我看来是有道理的,但这不正确。

0 个答案:

没有答案