[poj3140]Contestants Division树形dp】的更多相关文章

题意:切掉树上的某条边,使分开的两棵树上各点的权值和差值最小. 与hdu2196不同的是,此题是点权,其他无太大差别,注意数据范围. 先求出每个节点的子树权值和,然后自底向上dp即可.取$\min (abs(sum - 2*dp[u]))$ #include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> #include<cmath> #include<ios…
Contestants Division   Description In the new ACM-ICPC Regional Contest, a special monitoring and submitting system will be set up, and students will be able to compete at their own universities. However there’s one problem. Due to the high cost of t…
题目链接:传送门 题意: 给你一棵树,n个点 每个点可以染成红色和蓝色 但是红色的点与其相邻的点中必须有红色节点,蓝色也是 问你有多少种染色的方案 题解: 树形dp 先转化为有根树,取1为根 设定dp[now][red][red] 表示的是当前now节点然red色,其父亲节点染red色的可行方案数 转移很容易想到 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000…
题目链接:http://poj.org/problem?id=3140 题意: 给你一棵树,问你删去一条边,形成的两棵子树的节点权值之差最小是多少. 思路: dfs #include <iostream> #include <cstdio> #include <cstring> #include <vector> using namespace std; ; typedef long long LL; int n, cnt, head[N]; LL a[N]…
题目大意:一棵树,带点权.将这棵树分成两部分,找出使得两部分的点权和的差最小. 题目分析:直接dfs即可.找出每棵子树u的点权和size(u),如果以u和它的父节点之间的边为界,那么两边的点权和分别为sum-size(u)和size(u). 代码如下: # include<iostream> # include<cstdio> # include<cstring> # include<vector> # include<queue> # incl…
Contestants Division Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10704   Accepted: 3004 Description In the new ACM-ICPC Regional Contest, a special monitoring and submitting system will be set up, and students will be able to compete…
本文出自   http://blog.csdn.net/shuangde800 -------------------------------------------------------------------------------------- 题目链接:poj-3140 题目 给n个节点的带权树,删掉其中一边,就会变成两颗子树,    求删去某条边使得这这两颗子树的权值之差的绝对值最小. 思路 直接dfs一次,计算所有子树的权值总和tot[i]    如果删掉一条边(v, fa),fa…
<题目链接> 题目大意:给你一棵树,让你找一条边,使得该边的两个端点所对应的两颗子树权值和相差最小,求最小的权值差. 解题分析: 比较基础的树形DP. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; #define INF 0x7fffffff7fffffff #define clr(a,b) memset…
POJ 2378 Tree Cutting:题意 求删除哪些单点后产生的森林中的每一棵树的大小都小于等于原树大小的一半 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> using namespace std; ; <<; int t,n; int f[maxn]={}; int vis[maxn]={};…
id=3140">[POJ 3140] Contestants Division(树型dp) Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9121   Accepted: 2623 Description In the new ACM-ICPC Regional Contest, a special monitoring and submitting system will be set up, and stud…