zoukankan      html  css  js  c++  java
  • HihoCoder 1104 : Suzhou Adventure(树形DP)

    Suzhou Adventure

    时间限制:10000ms
    单点时限:1000ms
    内存限制:256MB

    描述

    Little Hi is taking an adventure in Suzhou now. There are N beautiful villages in Suzhou which are numbered from 1 to N. They connected by N-1 roads in such a way that there is excactly one way to travel from one village to another. Little Hi gives each village a score according to its attractiveness. He is visiting village 1 now and plans to visit excatly M villages (including village 1) and maxize the total score of visited villages. Further more, K villages are recommended by Little Ho. He does not want to miss these recommended villages no matter what their attractiveness scores are.

    Note that Little Hi visits every village on his travel route. Passing a village without visiting it is not allowed. Please find the maximum total score Little Hi can get.

    输入

    The first line contains 3 integers N(1 <= N <= 100), K(1 <= K <= 5) and M(1 <= M <= N), representing the number of villages, the number of recommended villages and the number of villages Little Hi plans to visit.
    The second line contains N integers, the attractiveness scores of villages. The scores are between 1 to 100.
    The third line contains K integers, the list of recommended villages.
    The following N-1 lines each contain two integers a and b, indicating that village a and village b are connected by a road.

    输出

    The maximum scores Little Hi can get. If there is no solution output -1.

    样例输入
    5 2 4
    1 2 3 4 5
    3 4
    1 2
    1 3
    1 4
    2 5
    样例输出
    10

    给出一些城市,每个城市有一个满意度,某一些城市是必须去的,且访问量受限制,求最大满意度。

    方法1,预处理得到必须访问的村庄集合,以便在动态规划时使用辅助决策,根据状态转移方程求解。可以理解为把缩点:必须要去的缩为1号点。

    方法2,把必须要去的城市加上一个很大的满意度,这样保证它一定会被选到。输出时再减去即可。

    这道题的数据有问题,就不贴代码了。

  • 相关阅读:
    手机传感器大科普:手机中的陀螺仪、加速器和磁力计
    安卓新导入工程中gen目录下无R文件解决方法
    自写的 c# 锚点,前端显示 读书 记事本(一)
    update access 不能更新
    NHibenate初学资源推荐(切肤之痛)
    ASP.NET页面刷新和定时跳转
    c#(或vb.net)程序改进 (转载)
    感恩节的一天
    了解自己以及明白牛人会找什么样的人创业
    从别人如何读简历 看我们该如何成长
  • 原文地址:https://www.cnblogs.com/hua-dong/p/7821100.html
Copyright © 2011-2022 走看看