zoukankan      html  css  js  c++  java
  • [USACO2002][poj1947]Rebuilding Roads(树形dp)

    Rebuilding Roads
    Time Limit: 1000MS Memory Limit: 30000K
    Total Submissions: 8589 Accepted: 3854
    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 cows didn't have time to rebuild any extra roads, so now there is exactly one way to get from any given barn to any other barn. Thus, the farm transportation system can be represented as a tree.

    Farmer John wants to know how much damage another earthquake could do. He wants to know the minimum number of roads whose destruction would isolate a subtree of exactly P (1 <= P <= N) barns from the rest of the barns.
    Input

    * Line 1: Two integers, N and P

    * Lines 2..N: N-1 lines, each with two integers I and J. Node I is node J's parent in the tree of roads.
    Output

    A single line containing the integer that is the minimum number of roads that need to be destroyed for a subtree of P nodes to be isolated.
    Sample Input

    11 6
    1 2
    1 3
    1 4
    1 5
    2 6
    2 7
    2 8
    4 9
    4 10
    4 11
    Sample Output

    2
    Hint

    [A subtree with nodes (1, 2, 3, 6, 7, 8) will become isolated if roads 1-4 and 1-5 are destroyed.]
    Source

    USACO 2002 February

    题意:给你一颗多叉的树,然后让你删除尽量少的边,得到一颗有p个节点的子树

    分析:

    明显这是一道树形dp

    f[i][j]表示以i为根的树,要成为j个节点的子树所需要删除的最少边数

    则f[i][j]=min(f[i][j-k]+f[son][k]-2)

    总结:

    此题很容易考虑f[i][j]和某个f[son][k]的关系,不过这样会发现状态转移时完全搜索级的……以后遇到这种情况的树形dp时候,可以换个角度考虑以同一个节点为根的子树不同j之间的转移。

  • 相关阅读:
    P7473 [NOI Online 2021 入门组] 重力球
    CF896D Nephren Runs a Cinema
    [持续更新]一些有趣的数学问题
    [微积分与无穷级数]AMM Problems笔记
    [补题]SWERC-2018
    [补题]Asia Regional Contest, Tokyo, 2014

    [NOI2005]瑰丽华尔兹-单调队列优化DP
    [补题]2017多校D-BD-区间筛/二分+线段树
    [补题]2017多校5A/HDU6085-Rikka with Candies-bitset优化
  • 原文地址:https://www.cnblogs.com/wmrv587/p/3583618.html
Copyright © 2011-2022 走看看