bzoj 1864 三色二叉树】的更多相关文章

传送门 题目大意: 给一颗二叉树染色红绿蓝,父亲和儿子颜色必须不同,两个儿子颜色必须不同,问最多和最少能染多少个绿色的. 题目分析: 裸的树型dp:\(dp[u][col][type]\)表示u节点染为col(0-绿色,1-红色,2-蓝色),当前求的是type(0-最小,1-最大)解. 然后最后输出最大为\(max(dp[1][0][1], dp[1][1][1], dp[1][2][1])\),最小为\(min(dp[1][0][0], dp[1][1][0], dp[1][2][0])\).…
Written with StackEdit. Description Input 仅有一行,不超过\(5*10^5\)个字符,表示一个二叉树序列. Output 输出文件也只有一行,包含两个数,依次表示最多和最少有多少个点能够被染成绿色. Sample Input 1122002010 Sample Output 5 2 Solution 一道比较水的树形\(dp\). 读入考察递归的使用.然后就是一个\(ex-\)没有上司的舞会. 令\(f[i][0/1/2]\)表示当\(i\)的颜色分别为…
难得的ZJOI水题...DFS一遍就行了... ----------------------------------------------------------------------- #include<cstdio> #include<cstring> #include<algorithm> #include<cctype>   using namespace std;   const int maxn = 500009;   int N = 0,…
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…
三色二叉树 问题描述 输入 仅有一行,不超过500000个字符,表示一个二叉树序列. 输出 输出文件也只有一行,包含两个数,依次表示最多和最少有多少个点能够被染成绿色. 样例输入 1122002010 样例输出 5 2   分析:简单树DP program tree1; var f,g:..,..]of longint; l,r:..]of longint; n,i,m,x,y,sum,len:longint; s:ansistring; function max(x,y:longint):lo…
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]三色二叉树 链接 分析: 做得最智障的一题了... 首先中间输出两个数之间没空格(换行居然也过了...), 写了dp[i][0/1/2],后来知道其实dp[i][0/1]就行了,最zz的一个bug,,,char pos = 1... 代码: #include<cstdio> #include<iostream> #define L ls[u] #define R rs[u] using namespace std; ; ],dp2[N][],pos…
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]]+…