Tribonacci单词是一个数字序列。这类似于斐波那契单词。Tribonacci Word是通过重复连接三个先前的字符串而构造的
T(n) = T(n - 1) + T(n - 2) + T(n - 3)
开始的前几个字符串是{1、12、1213},因此下一个字符串将是1213 + 12 +1 = 1213121
tribonacci_word(n): Begin first := 1, second := 12, third := 1213 print first, second, third for i in range 3 to n, do temp := third third := third + second + first print third first := second second := next done End
#include<iostream>
using namespace std;
long tribonacci_word_gen(int n){
//函数生成n个斐波那契数
string first = "1";
string second = "12";
string third = "1213";
cout << first << "\n" << second << "\n" << third << "\n";
string tmp;
for (int i = 3; i <= n; i++) {
tmp = third;
third += (second + first);
cout << third <<endl;
first = second;
second = tmp;
}
}
main(){
tribonacci_word_gen(6);
}输出结果
1 12 1213 1213121 1213121121312 121312112131212131211213 12131211213121213121121312131211213121213121