![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Tree
文章平均质量分 75
unixcsir
Coding Every Day~
展开
-
綫段樹練習-成段更新
hdu1698 Just a Hook poj3468 A Simple Problem with Integers原创 2012-07-22 13:05:11 · 296 阅读 · 0 评论 -
LA_3902 - Network
題意: 一個樹狀網絡,指定一個服務器s,一個距離k,與服務器相距爲k的節點都能被服務到,問服務整個網絡最少要增加多少臺服務器 分析: 這個網絡是無向的,轉成有向的比較好處理,題目給定了一個服務器,可以以這個點爲Root,把這個樹狀網絡變爲有向,然而比較優先的策略是從深度最深的葉子節點開始算距離爲k的位置放置一個服務器,然後更新覆蓋點,這裏只需要處理葉子節點,爲什麼? 因爲,如果葉子節點能被覆蓋的話原创 2013-04-11 19:24:27 · 388 阅读 · 0 评论 -
hdu_1102_Constructing Roads(最小生成樹)
題意: 給你一個帶權圖其中有一些道路已經建設完畢,求其最小生成樹 分析: 對於已經建設完畢的道路修改其費用爲0,然後使用Prim或者Kruskal都可以 Code: Prim #include #include #include #include #include #include #include #include #include #include #include #i原创 2013-04-09 09:09:12 · 445 阅读 · 0 评论 -
uva_10304 - Optimal Binary Search Tree(最优搜索二叉树)
最优二叉搜索树,根据二叉搜索树的性质,左子树的元素 < root < 右子树的元素 1.设cost[i][j] 表示从第i个结点到第j个结点的频率和 2.设min_cost[i,l,r] 表示以第l个结点到第r个结点的最优二叉搜索树的理想值,其中root = i 3.设dp[i][j] 表示区间为[i,j]结点组成的二叉搜索树的min_cost 4.min_cost[i,l,r] = min_c原创 2012-11-20 09:22:29 · 450 阅读 · 0 评论 -
Codeforces_9D_How many trees?
题意:给定高度h,并由n个结点编号为(1 ~ n),组成的二叉搜索数,高度比h高的数目 解题思路: 设dp[n][h]为n个结点组成高度为h的搜索二叉数的数目 1.设m为搜索二叉树的root结点,那么搜索二叉数的左子树的结点数为m-1,右子数的结点数为n-m 2.要使得该二叉搜索树的高度为h,那么考虑如下两种情况 2.1 左子树的高度 = h-1, 则右子树的高度可以为任意的[0,原创 2012-11-10 11:32:46 · 268 阅读 · 0 评论 -
hdu_1054_Strategic Game
树形dp,状态:dp[u][1], dp[u][0]分别表示第u个节点放与不放兵 状态转移方程表示为: dp[u][0] = sum{dp[v[1]}; dp[u][1] = sum{dp[v][0], dp[v][1]} ans = min(dp[root][0], dp[root][1]); #include #include #include using namespace std;原创 2012-11-08 12:09:50 · 234 阅读 · 0 评论 -
uva_327_Evaluating Simple C Expressions
#include #include #include #include using namespace std; #define MAXSPLIT 10 #define MAXVAL 27 #define MAXN 1001 char split[MAXN][MAXSPLIT]; int val_table[MAXVAL], mar原创 2012-11-07 21:17:05 · 419 阅读 · 0 评论 -
uva_699_The Falling Leaves
无需建树,递归写入数组,然后就是答案输出。 #include #include #define MAXN 1001 int rst[MAXN], val; void recusion_set_rst(const int &idx) { scanf("%d", &val); if( -1 != val ) { rst[i原创 2012-11-07 17:52:00 · 232 阅读 · 0 评论 -
uva_548_Tree
前序,中序建树,然后遍历 #include #include #include #include using namespace std; #define MAXN 700001 #define MAXCNT 10001 #define INF 0x3f3f3f3f char str[MAXN]; int rst, ans, in_cnt, post_cnt; int原创 2012-11-06 16:57:27 · 225 阅读 · 0 评论 -
uva_297_Quadtrees
题目中定义的四叉树,顶点若为黑色则一共有1024个像素,从这里可以推断出四叉数的曾数是6,最后一层的值为1, 思路是递归建树,然后遍历/ #include #include #include using namespace std; #define PARENT 1 #define FULL 2 #define EMPTY 3 #原创 2012-11-07 09:59:57 · 244 阅读 · 0 评论 -
uva_839_Not so Mobile
简单的建树,然后遍历 #include #include #include using namespace std; typedef struct BTREENODE_ { int lw, ld, rw, rd; struct BTREENODE_ *left_child; struct BTREENODE_ *right_child; }B原创 2012-11-08 10:32:16 · 310 阅读 · 0 评论 -
uva_712_S-Trees
题目描述比题目本身难啊。。。 #include #include #include using namespace std; #define MAXDEPTH 8 #define MAXN 1024 int main(int argc, char const *argv[]) { #ifndef ONLINE_JUDGE freopen原创 2012-11-07 11:42:35 · 443 阅读 · 0 评论 -
uva_112_Tree Summing
#include #include #include #include using namespace std; #define MAXN 1001 typedef struct _BTREENODE { int data; struct _BTREENODE *left_child; struct _BTREENODE *righ原创 2012-11-06 14:40:10 · 262 阅读 · 0 评论 -
uva_644_Immediate Decodability
这里运用了树的数据结构 先对串按照长度排序,然后遍历树,到达尾部的时候标记,当一个串行走在树的过程中,如果这个点已经标记了,那么说明这串的前缀是另一个串。 #include #include #include #include using namespace std; #define MAXN 3000 #define MAXCHAR 100 int hash[MAXN]; c原创 2012-10-27 14:47:49 · 197 阅读 · 0 评论 -
綫段樹練習-單點更新
hdu1166 敌兵布阵 hdu1754 I Hate It hdu1394 Minimum Inversion Number hdu2795 Billboard原创 2012-07-22 13:03:32 · 197 阅读 · 0 评论 -
uva_10859_Placing Lampposts( 樹形DP )
題意: 在一個n個節點,m條邊的無向無環圖中的節點中放置街燈,一個結點放置街燈那麼與這個結點爲頂點的邊都被照亮,使得每條邊都有被照亮的最少放置街燈的前提下,使得被兩個街燈照亮的邊儘量的多 分析: 在這裏的被兩個燈照亮的邊儘量的多,變一下:使得被一個燈照亮的邊儘量少 無向無環圖也就是森林, 對於求兩個變量的最小設一個等式: x = aM+c, 其中a是需要最少的燈,c是一個燈照亮的邊數量,目標就是使原创 2013-04-15 20:07:46 · 389 阅读 · 0 评论