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://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]…
本文出自   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…
题意: 有n个城市,构成一棵树,每个城市有v个人,要求断开树上的一条边,使得两个连通分量中的人数之差最小.问差的绝对值.(注意本题的M是没有用的,因为所给的必定是一棵树,边数M必定是n-1) 思路: 考虑当前节点t,当断开t与父亲的边时,“子树t中的人数”与“剩下的人数”之差的绝对值若最小,则为答案. //#include <bits/stdc++.h> #include <iostream> #include <cstdio> #include <cstring…
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]={};…
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…
题目链接 题意很扯,就是给一棵树,每个结点有个值,然后把图劈成两半,差值最小,反正各种扯. 2B错误,导致WA了多次,无向图,建图搞成了有向了.... #include <cstdio> #include <cstring> #include <iostream> #include <cmath> #include <algorithm> using namespace std; #define LL __int64 struct node {…
dp[x][y]表示以x为根的子树要变成有y个点..最少需要减去的边树... 最终ans=max(dp[i][P]+t)  < i=(1,n) , t = i是否为整棵树的根 > 更新的时候分为两种情况..一种是要从其这个孩子转移过来...枚举做01背包..更新出每个状态的最小值..或者说直接砍掉这个孩子..那么只需将所有的状态多加个砍边... 这里的枚举做01背包..意思是由于叶子节点要放多少进去不确定..叶子节点要放的大小以及本节点的空间都在枚举更新...这种概念就是泛化背包..本质上是0…
题意:一棵树每个结点上都有值,现删掉一条边,使得到的两棵树上的数值和差值最小. 思路:这个题我直接dfs做的,不知道树状dp是什么思路..一开始看到数据规模有些后怕,后来想到long long 可以达到10^18,我突然就释然了. 整体思路就是,先记录下整棵树的数值之和tot,然后对这棵树进行一遍dfs,每个结点都维护一个num值,num[x]表示结点x和它子树上的数值和.每求出一个结点的num值,就计算下tot - num[x]和num[x]的差值.dfs结束后最小的差值即为结果. 另外,要注…