题意:给定一个 n 个点和相应的权值,要求你用 n-1 条边连接起来,其中一条边是魔法边,不用任何费用,其他的边是长度,求该魔法边的两端的权值与其他边费用的尽量大. 析:先求出最小生成树,然后再枚举每一条边,求出最大值,任意两点之间的距离可以通过预处理来解决,最小生成树时,要用prime算法,要不然可能会超时. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #i…
斯坦纳树. 最后可以是森林,在计算出每个联通状态的最小费用后,还需要进行一次$dp$. #include<bits/stdc++.h> using namespace std; const int INF=0x7FFFFFFF; int T,n,m,k; vector<]; ][],id[],d[][],dp[]; *]; queue<int>Q; void spfa() { while(!Q.empty()) { ; ,y=h%; ;i<g[x].size();i++…
状态压缩dp+spfa解斯坦纳树 枚举子树的形态 dp[i][j] = min(dp[i][j], dp[i][k]+dp[i][l]) 当中k和l是对j的一个划分 依照边进行松弛 dp[i][j] = min(dp[i][j], dp[i'][j]+w[i][j])当中i和i'之间有边相连 #include <cstdio> #include <cstring> #include <queue> using namespace std; const int maxn…
Peach Blossom Spring http://acm.hdu.edu.cn/showproblem.php?pid=4085 Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Tao Yuanming(365-427) was a Chinese poet of Eastern Jin dynasty. One of his m…
discriptionTao Yuanming(365-427) was a Chinese poet of Eastern Jin dynasty. One of his most famous works is "Peach Blossom Spring", which is a fable about a chance discovery of an ethereal village where the people lead an ideal existence in harm…
Qin Shi Huang's National Road System HDU - 4081 感觉这道题和hdu4756很像... 求最小生成树里面删去一边E1 再加一边E2 求该边两顶点权值和除以(最小生成树-E1)的最大值 其中(最小生成树-E1)必须是最小的 先跑一遍prim 跑完之后在最小生成树里面dp dp[i][j] = i到j的路径中最大的那条边 最小生成树减去dp[i][j]肯定会最小 代码如下 #include <cstdio> #include <algorithm…
Abandoned country 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5723 Description An abandoned country has n(n≤100000) villages which are numbered from 1 to n. Since abandoned for a long time, the roads need to be re-built. There are m(m≤1000000) ro…
Minimal Ratio Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) [Problem Description] For a tree, which nodes and edges are all weighted, the ratio of it is calculated according to the following equation.Given a…
(1)集合中元素表示(1<<i), i从0开始 (2)注意dp[i][ss] = min(dp[i][ss], dp[i][rr | s[i]] + dp[i][(ss ^ rr) | s[i]]);,后面的要 |s[i],保证状态的正确 (3)INF初始化CLR(dp, 0x3f) (4)注意斯坦纳树状态理解,分层松弛的理解 参考:http://endlesscount.blog.163.com/blog/static/821197872012525113427573/ //#pragma…
HDU 1010 题目大意:给定你起点S,和终点D,X为墙不可走,问你是否能在 T 时刻恰好到达终点D. 参考: 奇偶剪枝 奇偶剪枝简单解释: 在一个只能往X.Y方向走的方格上,从起点到终点的最短步数为T1,并记其他任意走法所需步数为T2,则T2-T1一定为偶数. 即若某一点到终点的最短步数为T1,且T3-T1为奇数,则一定无法话费T3步恰好到达终点. /*HDU 1010 ------ Tempter of the Bone DFS*/ #include <cstdio> #include…