Test instructions: The topic gives a tree, each node has its weight. If you select a node, you cannot select its parent node and ask the maximum value that can be obtained.Analysis: A simple tree-shaped dp,dp[i][0] denotes node i is not selected, Dp[i][1] represents the node I select, the last selection of the maximum is good.The code is as follows:#pragma COMMENT (linker, "/stack:1024000000,1024000000") #include HDU 1520 Anniversary Party (tree-shape
Output
5
SourceUral State University Internal Contest October '2000 Students Session
Recommendlinle | We have carefully selected several similar problems for you: 1561 1011 2196 1494
I will give you a tree of interpersonal relationships, which is then mutually superior and subordinate (Parent and Child Nodes) cannot be selected at the same time.
Solution: tree-like dp, which can be expanded from one point at will. The dp of all nodes around it can be solved and then added.
Use dp [I] [0] to i
OUTPUT5Sourceural State University Internal Contest October ' Students SessionThe main idea is that there is a group of people have a relationship between the subordinate, in a party, there is a direct relationship between the subordinate (that is, the parent-child relationship in the tree) can not attend at the same time, everyone has a rating, smell how to choose to attend the people, so that all the rating and the biggest#include Analysis: Should be the most basic tree-shaped DP bar, accordi
Test instructions: To a tree, each node has the right value, requires the selection of some nodes out, so that the sum of the weight of the largest, but each pair (father, son) can only pick one.Ideas:Compare the Getting Started topic, each node can be selected or not selected. If the current node is selected, the child must not select all, and if the current node is not selected, then the child can choose or not to choose.1#include 2 #definePII pair3 #defineINF 0x3f3f3f3f4 #defineLL Long Long5
gradually a feeling that the ability to use data structure has been enhanced, that is, every time you want to realize what things feel will not be too difficult, perhaps because of the STL = good, Seriously don't know how to feel the DP and the base of recursion more and more like, but the key of DP, especially the tree-shaped DP seems to be found in the recursive relationship between the parent-child node, that is, the original linear that set of play method to move to the tree, more wonderful
The key to a tree DP is how to handle recursive return information. This question Dp[i][0] indicates that the current maximum weight is not selected when I point. DP[I][1] Indicates the current maximum weight when I point is selected. State transition equation: Dp[u][[0]+=max (dp[v][0],dp[v][1]), dp[u][1]+=dp[v][0];The code is as follows:#include HDU 1520 Anniversary Party (tree-shaped DP)
solution for I, the subtrees tree, that the employee comes from.Dp[u][0] + = Max{dp[v][0], dp[v][1]} v->uDP[U][1] + = max{dp[v][0]} v->u (v is the child node of U)DP[U][1] to give the initial value val[u] (happy value of u number)1#include 2#include 3#include 4 5 using namespacestd;6 Const intN =6010;7 intVal[n], dp[n][2], Flag[n], first[n], K;8 9 structedge{Ten inty, Next; One}e[n*n/2]; A - voidAdd_edge (intXinty) - { theE[k].y = y, E[k].next =First[x]; -FIRST[X] = k++; - } - + voidDfsin
Anniversary partyTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)Total submission (s): 5917 Accepted Submission (s): 2692Problem DescriptionThere is going-a party to celebrate the 80-th anniversary of the Ural state
There are n people, their relationship is a tree, each person has a joy, hold a party, invite some people in the individual, but if the relationship between the two is upper and lower level, up to one of them is invited.
Int DP [] [2] DP [] [0]
I recently studied simulated annealing. First, I would like to stamp it here> _
First, 20 random points are used as the ultimate solution to determine the farthest distance from the point closest to the factory. However, you need to pay attention
Very watery tree DP, the current status is I, the superior did not come Then you can perform a memory-based search. # Include # include # include # include # include # include # include # include # include # include # include # include #
Anniversary party
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission (s): 2124 Accepted Submission (s): 896Problem DescriptionThere is going to be a party to celebrate the 80-th Anniversary of the Ural
In terms of hardware, the 15 7000 series provides users with a very large choice of space, with a variety of hardware combinations, and this test is the 15 7000 series positioning high-end models, it is equipped with the fourth Daicouri i7-4500u low power processor, with 1TB hard drives, 8GB memory and Nvidia GeForce GT 750M standalone graphics, with considerable performance.
Of course, as the price of 8999 Yuan Notebook, the spirit of the 15 7000 series in addition to the outstanding hardware
A few days ago, I accidentally upgraded the XORG-SERVER package in DELLInspiron1520, and there were several more SERVER startup items in the GRUB menu, which was quite unpleasant, therefore, in Ubuntu7.10, I tried to use the # sudoapt-getremovexorg-server command to uninstall the package. Unexpectedly, a series of problems occurred. The first problem was that X could not be accessed, and the system prompts that the video card could not be found, after the video card driver is installed, the syst
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.