思路
- 递归运算
- 若可再分,就左子树递归,右子树递归
- 然后进行自身的计算即可
参考代码
#include<iostream>
using namespace std;
const int N = 15;
int n;
string str;
void Tree(int l,int r)
{
if(l!=r)Tree(l,(l+r)/2);
if(l!=r)Tree((l+r)/2+1,r);
int len0=0,len1=0;
string type;
for(int i=l;i<=r;++i){
if(str[i]=='0')len0++;
else len1++;
}
if(len1==0)type="B";
else if(len0==0)type="I";
else type="F";
cout<<type;
}
int main()
{
cin>>n;
cin>>str;
Tree(0,str.size()-1);
return 0;
}