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之间的转移。

  • 相关阅读:
    转载:SuperMap 网络带宽对B/S项目的影响有多大?如何计算所需要的带宽?
    转载:使用JWT做用户登陆token校验
    转载:互联网在线地图平台对比分析
    jmeter计时器讲解
    ReactNative setNativeProps
    关于xxx.h file not found 的问题
    注册推送通知
    ios ViewController present不同的方向
    ReactNative常见报错
    ios 后台模式
  • 原文地址:https://www.cnblogs.com/wmrv587/p/3583618.html
Copyright © 2011-2022 走看看