Jzoj4840 小W砍大树
模拟就好,dfs模拟,记录深度计算
#include<stdio.h>
#include<string.h>
char s[32010],*S;
int dijk(char*& s,int d){
int ret=(~d&1),v;
for(;*s!=')';++s){
if(*s=='('){ v=dijk(++s,d+1); ret=(d&1?ret|v:ret&v); }
if(*s=='T'){ v=1;ret=(d&1?ret|v:ret&v); }
if(*s=='F'){ v=0;ret=(d&1?ret|v:ret&v); }
}
return ret;
}
int main(){
freopen("form.in","r",stdin);
freopen("form.out","w",stdout);
for(int i=1;~scanf("%s",s);++i){
S=s+1;
printf("%d. %s\n",i,dijk(S,0)?"true":"false");
}
}