就是感觉很像线段树那样建树 然后统计01就行了
代码如下
#include<iostream>
#include<cstdio>
#include<cctype>
using namespace std;
#define in = read()
typedef long long ll;
typedef unsigned int ui;
const ll size = 1000 + 100;
int n;
int num0 , num1 , mid , ans;
char s[size];
inline ll read(){
ll num = 0 , f = 1; char ch = getchar();
while(!isdigit(ch)){
if(ch == '-') f = -1;
ch = getchar();
}
while(isdigit(ch)){
num = num*10 + ch - '0';
ch = getchar();
}
return num*f;
}
int pow(int a , int b){
ans = 1;
while(b){
if(b & 1) ans *= a;
a *= a; b >>= 1;
}
return ans;
}
void build(int l , int r){
mid = ((l + r)>>1);
if(l != r){
build(l , mid);
build(mid + 1 , r);
}
for(register int i=l;i<=r;i++){
if(s[i] == '0') num0 ++;
if(s[i] == '1') num1 ++;
}
if(num0 && num1) printf("F");
else if(!num1) printf("B");
else if(!num0) printf("I");
num0 = 0; num1 = 0;
}
int main(){
// freopen("fbi.in" , "r" , stdin);
// freopen("fbi.out" , "w" , stdout);
n in;
scanf("%s" , s + 1);
build(1 , pow(2 , n));
return 0;
}
//COYG