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

  • 相关阅读:
    推荐系统中的注意力机制——阿里深度兴趣网络(DIN)
    负样本采样及bias校准、ctr平滑
    todo提纲
    漫谈深度学习时代点击率预估技术进展 &&深度学习在推荐系统上的发展
    对数据分析的一点思考
    计算广告中常用深度学习网络
    pandas常见函数详细使用
    ann搜索算法(Approximate Nearest Neighbor)
    LintCode翻转字符串问题
    python常用库
  • 原文地址:https://www.cnblogs.com/wmrv587/p/3583618.html
Copyright © 2011-2022 走看看