Description Input 仅有一行,不超过500000个字符,表示一个二叉树序列. Output 输出文件也只有一行,包含两个数,依次表示最多和最少有多少个点能够被染成绿色. 记录每个节点染成每种颜色时以此节点为根的子树中绿色节点个数的最大值和最小值 信息由叶节点向上传递 #include<cstdio> int n; ,mxv=,mnv=; ,,,,,}; ]; ][]; ][]; inline void maxs(int&a,int b){if(a<b)a=b;}…
[BZOJ1864]三色二叉树(动态规划) 题面 BZOJ 题解 首先把树给构出来. 设\(f[i][0/1]\)表示当前节点\(i\),是否是绿色节点的子树中最大/最小的绿色节点的个数和. 转移很显然. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> #include…
1864: [Zjoi2006]三色二叉树 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 773  Solved: 548[Submit][Status][Discuss] Description Input 仅有一行,不超过500000个字符,表示一个二叉树序列. Output 输出文件也只有一行,包含两个数,依次表示最多和最少有多少个点能够被染成绿色. Sample Input 1122002010 Sample Output 5 2 HINT…
1864: [Zjoi2006]三色二叉树 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 659  Solved: 469[Submit][Status][Discuss] Description Input 仅有一行,不超过500000个字符,表示一个二叉树序列. Output 输出文件也只有一行,包含两个数,依次表示最多和最少有多少个点能够被染成绿色. Sample Input 1122002010 Sample Output 5 2 HINT…
1864: [Zjoi2006]三色二叉树 Description Input 仅有一行,不超过500000个字符,表示一个二叉树序列. Output 输出文件也只有一行,包含两个数,依次表示最多和最少有多少个点能够被染成绿色. Sample Input 1122002010 Sample Output 5 2 题解:经典的树形DP题.用f[i]表示点i是绿色时最多有多少个点能被染成绿色,g[i]表示i不是绿色时最多有多少个点被染成绿色,容易推出状态转移方程: f[i]=g[ch[i][0]]+…
http://www.lydsy.com/JudgeOnline/problem.php?id=1864 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define N 500001 char s[N]; int root; ]; int m; ],f[N][]; void dfs(int &rt) { rt=++m; '; if(!tmp) return…
1864: [Zjoi2006]三色二叉树 Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1195 Solved: 882 [Submit][Status][Discuss] Description Input 仅有一行,不超过500000个字符,表示一个二叉树序列. Output 输出文件也只有一行,包含两个数,依次表示最多和最少有多少个点能够被染成绿色. Sample Input 1122002010 Sample Output 5 2 HINT…
难得的ZJOI水题...DFS一遍就行了... ----------------------------------------------------------------------- #include<cstdio> #include<cstring> #include<algorithm> #include<cctype>   using namespace std;   const int maxn = 500009;   int N = 0,…
BZOJ_1864_[Zjoi2006]三色二叉树_树形DP 题意: 分析:递归建树,然后DP,从子节点转移. 注意到红色和蓝色没有区别,因为我们可以将红蓝互换而方案是相同的.这样的话我们只需要知道当前节点是否为绿色即可. 代码: #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; #define N 500050 int lson[N],rson[N],cnt…
1864: [Zjoi2006]三色二叉树 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 1295  Solved: 961[Submit][Status][Discuss] Description Input 仅有一行,不超过500000个字符,表示一个二叉树序列. Output 输出文件也只有一行,包含两个数,依次表示最多和最少有多少个点能够被染成绿色. Sample Input 1122002010 Sample Output 5 2 HINT…