「BZOJ1864」[ZJOI2006] 三色二叉树

2014年8月1日3,8971

Description

Input

仅有一行,不超过500000个字符,表示一个二叉树序列。

Output

输出文件也只有一行,包含两个数,依次表示最多和最少有多少个点能够被染成绿色。

Sample Input

1122002010

Sample Output

5 2

题解

随便dp一下即可

f[i][0/1]表示i结点为绿/非绿色的绿色结点的最大个数

转移

f[x][1]=f[l[x]][0]+f[r[x]][0]+1;
f[x][0]=max(f[l[x]][0]+f[r[x]][1],f[r[x]][0]+f[l[x]][1]);

最小值类似

 

 

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
0 Comment authors
Recent comment authors
  Subscribe  
提醒
maoxiaohan1999

orz 随便DP一下,