[BZOJ4557][JLOI2016]侦查守卫
4557: [JLoi2016]侦察守卫
Time Limit: 20 Sec Memory Limit: 256 MB
Submit: 297 Solved: 200
[Submit][Status][Discuss]
Description
Input
Output
仅一行一个整数,表示监视所有B神可能出现的点所需要的最小代价
Sample Input
8 9 12 6 1 1 5 1 4 8 10 6
10
1 2 3 5 6 7 8 9 10 11
1 3
2 3
3 4
4 5
4 6
4 7
7 8
8 9
9 10
10 11
11 12
Sample Output
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<iomanip>
using namespace std;
#define ll long long
#define db double
#define up(i,j,n) for(int i=j;i<=n;i++)
#define pii pair<int,int>
#define uint unsigned int
#define FILE "dealing"
#define eps 1e-4
int read(){
int x=0,f=1,ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return x*f;
}
template<class T> bool cmax(T& a,T b){return a<b?a=b,true:false;}
template<class T> bool cmin(T& a,T b){return a>b?a=b,true:false;}
const int maxn=505000,limit=50100,inf=1000000000,r=3,mod=1000000007;
int N,D;
struct node{
int y,next;
}e[maxn<<1];
int len=0,linkk[maxn],vis[maxn];
void insert(int x,int y){
e[++len].y=y;
e[len].next=linkk[x];
linkk[x]=len;
}
int f[maxn][22],g[maxn][22],w[maxn];
void dp(int x,int fa){
g[x][D+1]=inf;
if(vis[x])f[x][0]=g[x][0]=w[x];
up(i,1,D)g[x][i]=w[x];
for(int i=linkk[x];i;i=e[i].next){
int v=e[i].y;
if(v==fa)continue;
dp(v,x);
for(int j=D;j>=0;i--)g[x][j]=min(g[x][j+1],min(g[x][j]+f[v][j],g[v][j+1]+f[x][j+1]));
f[x][0]=g[x][0];
up(j,1,D+1)f[x][j]=min(f[x][j-1],f[x][j]+f[v][j-1]);
}
}
int main(){
freopen(FILE".in","r",stdin);
freopen(FILE".out","w",stdout);
N=read(),D=read();
up(i,1,N)w[i]=read();
int M=read();
up(i,1,M){
int x=read();
vis[x]=1;
}
up(i,2,N){
int x=read(),y=read();
insert(x,y);
insert(y,x);
}
dp(1,0);
cout<<f[1][0]<<endl;
return 0;
}
[BZOJ4557][JLOI2016]侦查守卫的更多相关文章
- JLOI2016 侦查守卫
侦查守卫 小R和B神正在玩一款游戏.这款游戏的地图由 N 个点和 N-1 条无向边组成,每条无向边连接两个点,且地图是连通的.换句话说,游戏的地图是一棵有 N 个节点的树. 游戏中有一种道具叫做侦查守 ...
- BZOJ 4557 JLOI2016 侦查守卫 树形dp
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=4557 题意概述: 给出一棵树,每个点付出代价w[i]可以控制距离和它不超过d的点,现在给 ...
- BZOJ4557 JLoi2016 侦察守卫 【树形DP】*
BZOJ4557 JLoi2016 侦察守卫 Description 小R和B神正在玩一款游戏.这款游戏的地图由N个点和N-1条无向边组成,每条无向边连接两个点,且地图是连通的.换句话说,游戏的地图是 ...
- BZOJ 4557 (JLOI 2016) 侦查守卫
4557: [JLoi2016]侦察守卫 Time Limit: 20 Sec Memory Limit: 256 MB Submit: 493 Solved: 342 [Submit][Status ...
- loj #2024. 「JLOI / SHOI2016」侦查守卫
#2024. 「JLOI / SHOI2016」侦查守卫 题目描述 小 R 和 B 神正在玩一款游戏.这款游戏的地图由 nnn 个点和 n−1n - 1n−1 条无向边组成,每条无向边连接两个点, ...
- bzoj4557【JLOI2016】侦查守卫
这道题对于我来说并不是特别简单,还可以. 更新一下blog 树形DP f[i][j]表示i的子树中,最高覆盖到i向下第j层的最小花费. g[i][j]表示i的子树全部覆盖,还能向上覆盖j层的最小花费. ...
- bzoj4557侦查守卫
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4557 树形DP.和“河流”有点像,也有一个类似“承诺”的东西. 就是用 f 表示当前节点向下 ...
- [BZOJ4557][JLOI2016]侦察守卫(树形DP)
首先可以确定是树形DP,但这里存在跨子树的信息传递问题,这里就需要“借”的思想. f[i][j]表示i子树内所有点都被覆盖到,且i以外j层内的点都能被覆盖到 的方案数. g[i][j]表示i子树内离i ...
- BZOJ4557 JLOI2016侦察守卫(树形dp)
下称放置守卫的点为监控点.设f[i][j]为i子树中深度最大的未被监视点与i的距离不超过j时的最小代价,g[i][j]为i子树中距离i最近的监控点与i的距离不超过j且i子树内点全部被监视时的最小代价. ...
随机推荐
- Exception:System.Threading.SemaphoreFullException
ylbtech-Error-Exception-C#: System.Threading.SemaphoreFullException 1.A,异常类型返回顶部 1,异常名称System.Thr ...
- 某音乐类App评论相关API的分析及SQL注入尝试
关键字:APIfen.工具使用.sql注入 涉及工具/包:Fiddler.Burpsuite.Js2Py.Closure Compiler.selenium.phantomjs.sqlmap 摘要: ...
- ubuntu更改mysql的编码配置
1.Ctrl+t打开终端 2.输入mysql -u root -p 命令,进入MySQL 输入 SHOW VARIABLES LIKE 'char%'; 查看MySQL编码,有两个不是utf8 3.在 ...
- H5 性能调优 工具
1.阿里测:http://www.alibench.com 2.奇云测:http://ce.cloud.360.cn 3.百度应用性能检测中心:http://apm.baidu.com 推荐理由:这3 ...
- Putty的噩梦——渗透工具PuttyRider使用心得分享
我们在入侵到一台主机的时候,经常会看到管理员的桌面会放着putty.exe,这说明有很大的可能性管理员是使用putty远程管理主机的. 该工具主要是针对SSH客户端putty的利用,采用DLL注入的方 ...
- 国内云引擎平台概览——新浪SAE,阿里ACE,百度BCE
新浪SAE 平时大家的測试server都是执行在自己的PC上面,用Tomcat或者IIS搭建的本机server. 事实上新浪云平台SinaAppEngine也是挺好用的. 今天总结一下我使用过程中的一 ...
- robot framework selenium2library定位
进行页面元素操作,最麻烦的莫过于元素定位了,经常提示element is not visible 或者element is not exist 下面介绍常见的定位方法和定位中的问题 1 使用name和 ...
- Java的Executor框架和线程池实现原理
Java的Executor框架 1,Executor接口 public interface Executor { void execute(Runnable command); } Executor接 ...
- win7查看端口占用
1.查看谁占用了我们的80端口,在windows命令行窗口下执行: netstat -aon|findstr 80 发现80端口被进程号为2596的进程占用.2.查看占用80端口进程的应用程序是什 ...
- 百度富文本编辑器Ueditor上传图片时标签中添加宽高
ueditor.all.js中:直接搜索callback() function callback(){ try{ var link, json, loader, body = (iframe.cont ...