从三个元素(例如1,2,3)的字符表中选取字符,生成一个有n个符号的序列,使得其中没有2个相邻的子序列相等。
如长度n = 5 的序列“12321”是合格的,而“12323”和“12123”都是不合格的,
因为“12323”中的“23”重复了、“12123”中的“12”重复了。
#include<iostream>
#include<iomanip>
using namespace std;
int n,a[11],ans=0;
void Recn(int dep)
{
if(dep>n)
{
for(int i=1;i<=_____(1)_____;i++)
cout<<setw(3)<<a[i];
cout<<endl;
_____(2)____;
return;
}
for(int i=1;i<=_____(3)______;i++)
{
a[dep]=_____(4)______;
bool flg1=true;
for(int len=1;len*2<=dep;len++)
{
bool flg2=false;
for(int j=dep;j>dep-len;j--)
{
if(a[j]!=a[_____(5)_____])
{
flg2=true;
break;
}
}
if(_____(6)_____)
{
flg1=false;
break;
}
}
if(flg1)
{
Recn(dep+1);
}
}
}
int main( )
{
cin>>n;
for(int i=1;i<=3;i++)
{
a[1]=i;
______(7)_____;
}
cout<<"ans="<<ans<<endl;
return 0;
}