poj 1694 An Old Stone Game 树形dp】的更多相关文章

//poj 1694 //sep9 #include <iostream> #include <algorithm> using namespace std; const int maxN=256; int n; int tree[maxN][maxN]; int ans[maxN]; int cmp(int a,int b) { return a>b; } int dfs(int u) { int tmp[maxN],t=0; if(tree[u][0]==0) retur…
一个公司的职员是分级制度的,所有员工刚好是一个树形结构,现在公司要举办一个聚会,邀请部分职员来参加. 要求: 1.为了聚会有趣,若邀请了一个职员,则该职员的直接上级(即父节点)和直接下级(即儿子节点)都不能被邀请 2.每一个员工都有一个兴奋值,在满足1的条件下,要使得邀请来的员工的兴奋值最高 输出最高的兴奋值. 简单的树形DP dp[i][1]:表示以i为根的子树,邀请节点i的最大兴奋值 dp[i][0]:表示以i为根的子树,不邀请节点i的最大兴奋值 先根据入度找出整棵树的根节点, 然后一次DF…
POJ 3162 『题目链接』POJ 3162 『题目类型』bit区间查询最值+树形DP ✡Problem: 一棵n个节点的树.wc爱跑步,跑n天,第i天从第i个节点开始跑步,每次跑到距第i个节点最远的那个节点(产生了n个距离),现在要在这n个距离里取连续的若干天,使得这些天里最大距离和最小距离的差小于M,问怎么取使得天数最多? ✡Answer: 参考:http://blog.csdn.net/angon823/article/details/52314522 这题和HDU 2196有相同的部分…
链接: http://poj.org/problem?id=1694 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27454#problem/E An Old Stone Game Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3132   Accepted: 1422 Description There is an old stone game, play…
https://vjudge.net/problem/POJ-2057 题意 有一只蜗牛爬上某个树枝末睡着之后从树上掉下来,发现后面的"房子"却丢在了树上面,.现在这只蜗牛要求寻找它的房子,它又得从树根开始爬起去找房子.现在要求一条路径使得其找到房子所要爬行的期望距离最小.房子等可能的出现在每个树枝末.某些分叉点会有虫子,会告知上次是否路过此地. 分析 有了虫子的存在,会影响我们遍历这棵树的路径,当虫子给出的信息是N时,就没必要走这个子树.所以问题就是设计一个期望值最小的路径. 设从r…
Rebuilding Roads Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 9957   Accepted: 4537 Description The cows have reconstructed Farmer John's farm, with its N barns (1 <= N <= 150, number 1..N) after the terrible earthquake last May. The…
题目: Description There is an old stone game, played on an arbitrary general tree T. The goal is to put one stone on the root of T observing the following rules: At the beginning of the game, the player picks K stones and puts them all in one bucket. A…
题目传送门//res tp poj 题意 给出一棵有权树,求一个节点集的权值和,满足集合内的任意两点不存在边 分析 每个点有选中与不选中两种状态,对于第\(i\)个点,记选中为\(sel_i\),不选中为\(insel_i\) 若某一节点选中,则其子节点都不能选中. 若某一节点不选中,则其子节点有两种选择:1.选中 2.不选中 故 \[sel_i = val_i +\sum_j insel_j\] \[insel_i = \sum_j max\{insel_j,sel_j\}\] 其中\(j\)…
Anniversary party Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5523   Accepted: 3169 Description There is going to be a party to celebrate the 80-th Anniversary of the Ural State University. The University has a hierarchical structure…
大致题意:在某个点派出两个点去遍历全部的边,花费为边的权值,求最少的花费 思路:这题关键好在这个模型和最长路模型之间的转换.能够转换得到,全部边遍历了两遍的总花费减去最长路的花费就是本题的答案,要思考.并且答案和派出时的起点无关 求最长路两遍dfs或bfs就可以,从随意点bfs一遍找到最长路的一个终点,再从这个终点bfs找到起点 //1032K 79MS C++ 1455B #include<cstdio> #include<iostream> #include<cstrin…