题目大意 给定一棵n个结点的树,每个结点上有一定数量的treasure,经过每条边需要花一定的时间,要求你从结点1出发,在不超过时间T的情况下,最多能够获得的treasure是多少,并且要求结束于结点n 题解 本题主要的困难是如何恰好结束于结点n. 先进行一次dfs求出从结点1到结点n的最短时间s(假设此条路径为a),如果s比T还大,不能走完,输出-1.否则的话继续处理,由于路径a是最短路径,因此肯定会经过此条路径,并且只会经过一次,其他的结点要么不经过,要么经过两次(因此时间花费是边权的两倍)…
Problem Description My name is Hu Bayi, robing an ancient tomb in Tibet. The tomb consists of N rooms (numbered from 1 to N) which are connected by some roads (pass each road should cost some time). There is exactly one route between any two rooms, a…
题目大概说一棵n个结点树,每个结点都有宝藏,走过每条边要花一定的时间,现在要在t时间内从结点1出发走到结点n,问能获得最多的宝藏是多少. 放了几天的题,今天拿出来集中精力去想,还是想出来了. 首先,树上任意两点间最短的那条路径是唯一的,且不管怎么走一定都会走过那条路径上的所有点,也就是说整个行程可以看成两部分组成:一部分就是1到n的最短路径,另一部分就是从这个路径上的某点出发绕回该点的路径. 这样问题就清晰了,现在关键在求第二部分: 先用树上背包求出:dp[u][t],表示从在以u点为根的子树中…
题目大意:在一个n个节点的树形迷宫中,1为起点,n为出口.每个节点上有一定价值的珠宝,在节点之间移动的时间已知,问在能走出迷宫的前提下并且不超过m的时间内能收集的最多珠宝是多少? 题目分析:在树上,从1到n的路径唯一.从1到n的唯一路径叫做主线路,要想走到出口,一定会经过主线路,也就是必须经过主线路上节点.在脱离主线路之前必须要预留出返回的时间. 代码如下: # include<iostream> # include<cstdio> # include<vector>…
题目的介绍以及思路完全参考了下面的博客:http://blog.csdn.net/acm_cxlove/article/details/7964739 做这道题主要是为了加强自己对SPFA的代码的训练以及对树dp的一些思路的锻炼.我特地研究了一下树dp的部分 for (int i = t; i >= w; i--){ for (int j = i-w; j >= 0; j--){ dp[u][i] = max(dp[u][i], dp[u][j]+dp[v][i - j - w]); } }…
The Ghost Blows Light Problem Description My name is Hu Bayi, robing an ancient tomb in Tibet. The tomb consists of N rooms (numbered from 1 to N) which are connected by some roads (pass each road should cost some time). There is exactly one route be…
K - The Ghost Blows Light Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4276 Appoint description:  System Crawler  (2015-10-20) Description My name is Hu Bayi, robing an ancient tomb in Tibet.…
The Ghost Blows Light Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 427664-bit integer IO format: %I64d      Java class name: Main     My name is Hu Bayi, robing an ancient tomb in Tibet. The tomb consists…
这个题目给定一棵树,以及树的每个树枝的苹果数量,要求在保留K个树枝的情况下最多能保留多少个苹果 一看就觉得是个树形DP,然后想出 dp[i][j]来表示第i个节点保留j个树枝的最大苹果数,但是在树形过程中,有点难表示转移 后来看了下大神的做法才知道其实可以用背包来模拟 树枝的去留,其实真的是个背包诶,每个子树枝就相当于物品,他占用了多少树枝量,带来多少的收益,就是用背包嘛,于是用树形DP+背包就可以做了 #include <iostream> #include <cstdio> #…
题意:给出一棵n个节点的树,起点1,终点n,相连的两个节点之间有距离,每个节点有个价值,给出一个时间T.问从1到达n在给定时间T内取得的最大价值? 思路:先从1走到n,如果总的时间不够走完,直接退出,否则把时间扣掉,这些边权设置为0,然后做一遍树形DP #include<algorithm> #include<cstdio> #include<cmath> #include<cstring> #include<iostream> int n,m;…