http://acm.hdu.edu.cn/showproblem.php?pid=5290

题意:

一棵树,每个点有一个权值wi,选择点i即可破坏所有距离点i<=wi的点,问破坏所有点 最少需要选择多少个点

题解:同JLOI2016 侦察守卫

http://www.cnblogs.com/TheRoadToTheGold/p/8544819.html

#include<cstdio>
#include<cstring>
#include<iostream> using namespace std; #define N 100001 int d;
int w[N];
bool use[N]; int front[N],to[N<<],nxt[N<<],tot; int f[N][],g[N][]; void read(int &x)
{
x=; char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
} void add(int u,int v)
{
to[++tot]=v; nxt[tot]=front[u]; front[u]=tot;
to[++tot]=u; nxt[tot]=front[v]; front[v]=tot;
} void dfs(int x,int fa)
{
for(int i=;i<=w[x];++i) f[x][i]=;
for(int i=w[x]+;i<=;++i) f[x][i]=N+;
g[x][]=;
for(int i=;i<=;++i) g[x][i]=;
int t;
for(int i=front[x];i;i=nxt[i])
{
t=to[i];
if(t!=fa)
{
dfs(t,x);
for(int j=;j<=;++j) f[x][j]=min(f[x][j]+g[t][j],f[t][j+]+g[x][j+]);
for(int j=;j>=;--j) f[x][j]=min(f[x][j],f[x][j+]);
g[x][]=f[x][];
for(int j=;j<=;++j) g[x][j]+=g[t][j-];
for(int j=;j<=;++j) g[x][j]=min(g[x][j],g[x][j-]);
}
}
} int main()
{
int n,m,u,v;
while(scanf("%d",&n)!=EOF)
{
tot=;
memset(front,,sizeof(front));
for(int i=;i<=n;++i) read(w[i]);
int u,v;
for(int i=;i<n;++i)
{
read(u); read(v);
add(u,v);
}
dfs(,);
printf("%d\n",g[][]);
}
return ;
}

hdu 5290 Bombing plan的更多相关文章

  1. 2015 Multi-University Training Contest 1 hdu 5290 Bombing plan

    Bombing plan Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)To ...

  2. hdu 4022 Bombing

    Bombing Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Sub ...

  3. HDU 3080 The plan of city rebuild(prim和kruskal)

    The plan of city rebuild Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java ...

  4. HDU 3757 Evacuation Plan DP

    跟 UVa 1474 - Evacuation Plan 一个题,但是在杭电上能交过,在UVa上交不过……不知道哪里有问题…… 将施工队位置和避难所位置排序. dp[i][j] 代表前 i 个避难所收 ...

  5. HDU 4671 Backup Plan (2013多校7 1006题 构造)

    Backup Plan Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total ...

  6. HDU 3080 The plan of city rebuild(除点最小生成树)

    题意  一个城市原来有l个村庄 e1条道路  又添加了n个村庄 e2条道路  后来后销毁了m个村庄  与m相连的道路也销毁了  求使全部未销毁村庄相互连通最小花费  不能连通输出what a pity ...

  7. [HDU5290]Bombing plan

    vjudge sol 树DP. 首先把模型转换成:每个点可以控制与它距离不超过\(w_i\)的点,先要求选出数量最少的点控制所有点. 设\(f[i][-100...100]\)表示\(i\)号点向上还 ...

  8. HDU 2103 Family Plan

    题目HDU 2103:http://acm.hdu.edu.cn/showproblem.php?pid=2103 Problem Description As far as we known,the ...

  9. HDU 4022 Bombing(stl,map,multiset,iterater遍历)

    题目 参考了     1     2 #define _CRT_SECURE_NO_WARNINGS //用的是STL中的map 和 multiset 来做的,代码写起来比较简洁,也比较好容易理解. ...

随机推荐

  1. Flask学习-Flask基础之WSGI

    一.WSGI为什么会出现? 在学习一个东西之前,我们肯定想知道:它为什么会出现?那么,WSGI为什么会出现呢? 我们知道,部署一个web应用,经常需要使用nginx.apache或者IIS等web服务 ...

  2. docker 学习笔记(2)--doucker file命令

    FROM base       ---- imageRUN                  ---- 执行命令ADD   ---- 添加文件COPY         ---- 拷贝文件CMD    ...

  3. CentOS7使用winbind加入AD

    https://ishm.idv.tw/?p=336 CentOS 7 使用 winbind 加入 AD 需求:已經熟悉 CentOS 6 的 AD 加入方式,CentOS 7 已將 winbind ...

  4. Codeforces Round #546 (Div. 2) E - Nastya Hasn't Written a Legend

    这题是一个贼搞人的线段树 线段树维护的是 区间和a[i - j] 首先对于update的位置可以二分查找 其次update时候的lazy比较技巧 比如更新的是 l-r段,增加的是c 那么这段的值为: ...

  5. mysql 插多行数据

    应用场景: 需要把一个表(tableA)的个别字段筛选出来,添加到新表中(tableB).新表还含有其他字段,主键是uuid. 思路解析: 熟悉插入一行数据的sql语句: insert into cu ...

  6. C语言版本:循环单链表的实现

    SClist.h #ifndef __SCLIST_H__ #define __SCLIST_H__ #include<cstdio> #include<malloc.h> # ...

  7. C++:钻石继承与虚继承

    QUESTION:什么是钻石继承? ANSWER:假设我们已经有了两个类Father1和Father2,他们都是类GrandFather的子类.现在又有一个新类Son,这个新类通过多继承机制对类Fat ...

  8. 祝贺自己操作系统JAVA项目有进展!!

    先公布研发过程的心得吧!!! ^_^ /** * 作者:范铭祥 * 内容及功能: 显示框创造1.0 * 我将在这个类里 一:面板1:用来先显示一副图表示顺序和处理中 * 二:面板2:类1:用来显示要处 ...

  9. C#简述(一)

    详情请参考:http://www.runoob.com/csharp/csharp-tutorial.html 1.C# 是一个简单的.现代的.通用的.面向对象的编程语言,它是由微软(Microsof ...

  10. Software-Defined Networking:A Comprehensive Survey--Day2

    Software-Defined Networking:A Comprehensive Survey (续+1s) IV. SOFTWARE-DEFINED NETWORKS: BOTTOM-UP S ...