[JZOJ 5819] 大逃杀
题意:求一个树上背包~~
先贴代码存一下,好像打挂了。
#include <bits/stdc++.h>
using namespace std;
const int maxn = 400;
const int INF = 0x3c;
int dp[maxn][maxn][3];
inline int read() {
int q=0,f=1;char ch = getchar();
while(!isdigit(ch)){
if(ch=='-')f=-1;ch=getchar();
}
while(isdigit(ch)){
q=q*10+ch-'0';ch=getchar();
}
return q*f;
}
int cnt;
int head[maxn << 1];
int n,m,t;
struct edge {
int to;
int nxt;
int w;
}e[maxn << 1];
int ans;
inline void Add_edge(int u,int v,int w) {
e[++cnt].to = v;
e[cnt].nxt = head[u];
head[u] = cnt;
e[cnt].w = w;
e[++cnt].to = u;
e[cnt].nxt = head[v];
head[v] = cnt;
e[cnt].w = w;
}
int s[maxn];
int cost[maxn];
inline void dfs(int x,int fa) {
for(int i = 0;i <= t; ++i) {
if(i < s[x]) {
dp[x][i][0] = dp[x][i][1] = dp[x][i][2] = -INF;
}
else {
dp[x][i][0] = dp[x][i][1] = dp[x][i][2] = cost[x];
}
}
for(int i = head[x];i;i=e[i].nxt) {
int y = e[i].to;
if(y != fa) {
dfs(y,x);
for(int j = t;j >= e[i].w; --j) {
for(int k = 0;k <= j - e[i].w; ++k) {
if(j - k >= 2 * e[i].w) {
dp[x][j][2] = max(dp[x][j][2],dp[y][k][0] + dp[x][j - 2 * e[i].w - k][2]);
}
if(j - k >= 2 * e[i].w) dp[x][j][2] = max(dp[x][j][2],dp[y][k][2] + dp[x][j - k - 2 * e[i].w][0]);
dp[x][j][2] = max(dp[x][j][2],dp[y][k][1] + dp[x][j - k - e[i].w][1]);
if(j - k >= 2 * e[i].w) {
dp[x][j][1] = max(dp[x][j][1],dp[y][k][0] + dp[x][j - k - 2 * e[i].w][1]);
}
dp[x][j][1] = max(dp[x][j][1],dp[y][k][1] + dp[x][j - k - e[i].w][0]);
if(j - k >= 2 * e[i].w) {
dp[x][j][0] = max(dp[x][j][0],dp[y][k][0] + dp[x][j - k - 2 * e[i].w][0]);
}
}
}
}
}
}
int main () {
freopen("toyuq.in","r",stdin);
freopen("toyuq.out","w",stdout);
n = read(),t = read();
for(int i = 1;i <= n; ++i) {
cost[i] = read();
}
for(int i = 1;i <= n; ++i) {
s[i] = read();
}
for(int i = 1;i < n; ++i) {
int x = read(),y = read(),z = read();
Add_edge(x,y,z);
}
dfs(1,0);
for(int i = 1;i <= n; ++i) {
ans = max(ans,dp[i][t][2]);
}
printf("%d\n",ans);
return 0;
}
[JZOJ 5819] 大逃杀的更多相关文章
- 绝地求生大逃杀BE启动失败,应用程序无法正常启动
今日更新绝地求生大逃杀后部分客户反馈绝地求生点击启动提示BE安装,应用程序无法启动 问题原因:经过排查发现,客户开启过超级工作站运行过游戏,在系统镜像包中保留了旧版的BE服务,致使新版BE无法安装,冲 ...
- 《绝地求生大逃杀》BE错误怎么办 BE服务未正常运行及安装失败解决方法
<绝地求生大逃杀>BattlEye Launcher是游戏的反作弊程序,也是启动过程中做容易出现错误的,今天小编带来“爆锤吧务”分享的<绝地求生大逃杀>BE服务未正常运行及安装 ...
- 洗礼灵魂,修炼python(41)--巩固篇—从游戏《绝地求生-大逃杀》中回顾面向对象编程
声明:本篇文章仅仅以游戏<绝地求生>作为一个参考话题来介绍面向对象编程,只是作为学术引用,其制作的非常简易的程序也不会作为商业用途,与蓝洞公司无关. <绝地求生>最近很火,笼络 ...
- 大逃杀(树上dp)
这道题和宝藏差不多吧,转移的时候比较麻烦的. 代码中分量很多种情况. h更新比较麻烦 这两幅图表示了双边更新中3,4连个h更新,下面比较好理解的吧. #include<cstring> # ...
- uSurvival 1.41多人在线生存逃杀吃鸡类游戏源码
uSurvival - the new Multiplayer Survival Asset from the creator of uMMORPG. Features:* Kill Zombies ...
- Movies
码头风云欲望号街车 不可思议的收缩人 The Incredible Shrinking Man (1957) 风之谷 西域威龙 对话 天地无限 现代启示录 黑暗之心 Hearts of Darknes ...
- ue4构建光照失败问题与解决
不知从哪天开始,我的ue4.13就突然无法成功构建光照了, 症状为:虽然swarm连接到了100%,然而之后就卡住一动不动,一看看log是连接tcp什么agent什么失败的. 虽然把所有物体都设置成非 ...
- 3D位置语音,引领吃鸡游戏体验升级
欢迎大家前往云加社区,获取更多腾讯海量技术实践干货哦~ 作者:腾讯游戏云 导语:在刚刚结束的首届腾讯用户开放日上,腾讯音视频实验室带着3D位置音效解决方案,向所有用户亮相,为用户提供360度立体空间的 ...
- Software Engineering-HW1
title: Software Engineering-HW1 date: 2017-09-13 15:41:13 tags: HW --- 阅读随笔 在<徐宥:掉进读书的兔子洞>里面, ...
随机推荐
- leetcode-161周赛-5249-移除无效的括号
题目描述: 自己的提交:O(N) class Solution: def minRemoveToMakeValid(self, s: str) -> str: #from collections ...
- mongodb 查询指定字段
@AutowiredMongoDatabase database; @Overridepublic List<Grid> getAdditionalGrid(String collecti ...
- adb devices unauthorized的解决办法
Hi, trying to launch adb but get: daemon not running. starting it now on port * daemon started s ...
- 14、testng.xml 设置用例执行顺序
目录如下: TestGroup.java 代码如下: package com.testng.cn; import org.testng.annotations.*; import static org ...
- 2019杭电多校第三场hdu6606 Distribution of books(二分答案+dp+权值线段树)
Distribution of books 题目传送门 解题思路 求最大值的最小值,可以想到用二分答案. 对于二分出的每个mid,要找到是否存在前缀可以份为小于等于mid的k份.先求出这n个数的前缀和 ...
- POJ3630-Phone List-Trie字典树模板题
Given a list of phone numbers, determine if it is consistent in the sense that no number is the pref ...
- 作用域 {}代码块 const修饰符 引用
简单分为:全局作用域.局部作用域.语句作用域 如果希望在局部变量的作用域内使用同名的全局变量,可以在该变量前加上“::” ::aver=20 #include<iostream> usin ...
- Vue 学习笔记之 —— 组件(踩了个坑)
最近在学习vue,学习组件时,遇到了一个问题,困扰了半个多小时.. <!DOCTYPE html> <html lang="en"> <head> ...
- next()nextLine()以及nextInt()的区别及用法【转载】
next().nextLine().nextInt()作为scanner内置的方法,常常让人傻傻分不清楚,今天在这里记下他们的区别以及以此区别为出发点的用法:他们的区别在于对于空格的处理方式不同,以及 ...
- firewall防火墙配置
获取所有zone firewall-cmd --list-all-zones 重启服务 firewall-cmd --complete-reload 名词解释 在具体介绍zone之前学生先给大家介绍几 ...