Dynamic Planning (II)-tree DP

Source: Internet
Author: User
Preface

\ (DP \) is really profound and profound ......

Introduction

Tree \ (DP \)As the name suggests, it is the \ (DP \) operated on the tree. Generally, \ (f_ I \) can be used to represent the optimal solution in the subtree with the node numbered \ (I \) as the root.

During the transfer, the information is generally transferred from the child node to the Father's Day point, that is, the information is transferred from the bottom up.

Therefore, the tree \ (DP \) usually usesRecursion.

Example 1: Tree backpack

Tree \ (DP \) has a classic question type:Tree backpack.

In fact, its thoughts andOrdinary backpackThe key lies in the time complexity of its metaphysics.

Many seemingly \ (O (N ^ 3) \) will \ (T \) Fly (Actually, it does.), Maybe you can use \ (O (N ^ 3) \) to carry a backpack on the tree (I will not prove the time complexity ),And not because of data.

For more information, see [Luogu 1273.

Example 2: diameter of the weighted tree

The diameter of a common tree can be obtained by \ (BFS \). However, if it is weighted, \ (BFS \) will be cracked (Unfortunately, I did not know before.).

So I used it.Tree \ (DP \).

You can refer to an example: [Miscellaneous] access plan.

Examples

Well, \ (DP \) seems to have nothing to talk about. This is not detailed enough. Let's take a look at the example.

Example 1:[51nod1299] fleeing from prison

This is an interesting tree \ (DP \) question. We can consider using the \ (f \) array to record the status of each node:Completely blocked,This node can be used to reach the leaf node.,A prisoner can reach this node.Then it is not difficult to calculate the answer.

Example 2:[Bzoj4033] [haoi2015] tree Dyeing

Typical tree \ (DP \) questions. The most noteworthy part of this question is not the \ (DP \) process, but the attentionIn a tree with \ (n \) nodes, it is equivalent to dyeing \ (M \) nodes black and \ (n-m \) nodes black.Without this optimization, it will \ (TLE \).

Example 3:[Bzoj1040] [zjoi2008] server guard

A disgustingBase ring outward tree \ (DP \)It should be a comparison template.

Dynamic Planning (II)-tree DP

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.