hdu 5290 Bombing plan
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的更多相关文章
- 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 ...
- hdu 4022 Bombing
Bombing Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)Total Sub ...
- 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 ...
- HDU 3757 Evacuation Plan DP
跟 UVa 1474 - Evacuation Plan 一个题,但是在杭电上能交过,在UVa上交不过……不知道哪里有问题…… 将施工队位置和避难所位置排序. dp[i][j] 代表前 i 个避难所收 ...
- HDU 4671 Backup Plan (2013多校7 1006题 构造)
Backup Plan Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
- HDU 3080 The plan of city rebuild(除点最小生成树)
题意 一个城市原来有l个村庄 e1条道路 又添加了n个村庄 e2条道路 后来后销毁了m个村庄 与m相连的道路也销毁了 求使全部未销毁村庄相互连通最小花费 不能连通输出what a pity ...
- [HDU5290]Bombing plan
vjudge sol 树DP. 首先把模型转换成:每个点可以控制与它距离不超过\(w_i\)的点,先要求选出数量最少的点控制所有点. 设\(f[i][-100...100]\)表示\(i\)号点向上还 ...
- HDU 2103 Family Plan
题目HDU 2103:http://acm.hdu.edu.cn/showproblem.php?pid=2103 Problem Description As far as we known,the ...
- HDU 4022 Bombing(stl,map,multiset,iterater遍历)
题目 参考了 1 2 #define _CRT_SECURE_NO_WARNINGS //用的是STL中的map 和 multiset 来做的,代码写起来比较简洁,也比较好容易理解. ...
随机推荐
- docker之镜像管理命令
一.docker image 镜像管理命令 指令 描述ls 列出本机镜像build 构建镜像来自Dockerfilehistory 查看镜像历史inspect 显示一个或多个镜像详细信息pull 从镜 ...
- AssetBundleMaster
AssetBundleMaster is an integrated solution for build AssetBundle and load assets from AssetBundles ...
- 谈谈我对Manacher算法的理解
Manacher算法其实是求字符串里面最长的回文. ①在学习该算法前,我们应该知道回文的定义:顺序读取回文和逆序读取回文得到的结果是一样的,如:abba,aba. 那么我们不难想到,在判断一个字符串s ...
- PAT甲题题解-1059. Prime Factors (25)-素数筛选法
用素数筛选法即可. 范围long int,其实大小范围和int一样,一开始以为是指long long,想这就麻烦了该怎么弄. 而现在其实就是int的范围,那难度档次就不一样了,瞬间变成水题一枚,因为i ...
- 团队博客 Week14
0. 在吹牛之前,先回答这个问题: 如果你的团队来了一个新队员,有一台全新的机器, 你们是否有一个文档,只要设置了相应的权限,她就可以根据文档,从头开始搭建环境,并成功地把最新.最稳定版本的软件编译出 ...
- ElasticSearch 2 (3) - Breaking Changes
ElasticSearch 2.1.1 (3) - Breaking Changes Search Changes search_type = scan Deprecated GET /my_ind ...
- beta yz 5
031602111 傅海涛 1.今天进展 接口微调修正 2.存在问题 文档转化太久 3.明天安排 完成全部接口的交互 4.心得体会 文档转化需要好好优化 031602115 黄家雄 1.界面优化 2. ...
- Python爬虫实战:2017中国最好大学排名
抓取内容: 从最好大学网上抓取中国前10的大学排名.大学名称.总分,并数据格式左对齐. http://www.zuihaodaxue.cn/zuihaodaxuepaiming2017.html 首先 ...
- 如何使用js判断视频是否可以成功访问
日常工作中会出现各个公司网络不互通的情况,视频如果采用不互通的地址也无法播放,下面方法提供了检测视频是否可以播放的解决方案: 1.跨域 var video = document.createEleme ...
- python自动化之excel
import openpyxl wb=openpyxl.load_workbook(r'C:\Users\Administrator\Desktop\sl.xlsx') type(wb) wb.get ...