【CodeVS 1163】访问艺术馆
http://codevs.cn/submission/2367697/
loli蜜汁(面向高一)树形dp是这道题的改编。
改编后的题目中每个展览厅的有多个不同的画,偷画的时间和画的价值也不同,求最大价值。
需要在叶节点上做01背包。
但codevs上的这道题就简单多了,直接改了改01背包交上去A了。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct nodeTreeDP {
struct node {int nxt, to;} E[100003];
int cnt, val[103], point[50003], f[103][603], m, tot;
nodeTreeDP() {
cnt = 0; tot = 1;
memset(E, 0, sizeof(E));
memset(f, 0, sizeof(f));
memset(point, 0, sizeof(point));
}
void ins(int u, int v) {E[++cnt] = (node) {point[u], v}; point[u] = cnt;}
void dfsread(int from) {
int t, x;
scanf("%d%d", &t, &x);
++tot;
ins(from, tot);
val[tot] = t << 1;
if (x) {
int w, c; w = 1; c = 5;
for(int i = 1; i <= x; ++i) {
for(int j = 600; j >= 0; --j)
if (j - (t << 1) - c >= 0)
f[tot][j] = max(f[tot][j], f[tot][j - c] + w);
}
} else {
int now = tot;
dfsread(now);
dfsread(now);
}
}
void readin() {
int t, x;
scanf("%d%d", &t, &x);
val[1] = t << 1;
if (!x) {
dfsread(1);
dfsread(1);
} else {
int w, c; w = 1; c = 5;
for(int i = 1; i <= x; ++i) {
for(int j = 600; j >= 0; --j)
if (j - (t << 1) - c >= 0)
f[1][j] = max(f[1][j], f[1][j - c] + w);
}
}
}
void TreeDP(int x) {
for(int i = point[x]; i; i = E[i].nxt)
TreeDP(E[i].to);
if (!point[x]) return;
int left = 0, right = 0;
for(int i = point[x]; i; i = E[i].nxt) {
if (!left) left = E[i].to;
else right = E[i].to;
}
for(int top = val[x]; top <= 600; ++top) {
int res = top - val[x];
for(int leftnum = 0; leftnum <= res; ++leftnum) {
int rightnum = res - leftnum;
f[x][top] = max(f[x][top], f[left][leftnum] + f[right][rightnum]);
}
}
}
void ansit() {
TreeDP(1);
printf("%d\n", f[1][m]);
}
} *T;
int main() {
T = new nodeTreeDP;
scanf("%d", &T->m);
T->readin();
T->ansit();
return 0;
}
【CodeVS 1163】访问艺术馆的更多相关文章
- codevs 1163 访问艺术馆
1163 访问艺术馆 时间限制: 1 s 空间限制: 128000 KB 题目描述 Description 皮尔是一个出了名的盗画者,他经过数月的精心准备,打算到艺术馆盗画.艺术馆的结 ...
- Codevs No.1163 访问艺术馆
2016-05-31 20:48:47 题目链接: 访问艺术馆 (Codevs No.1163) 题目大意: 一个贼要在一个二叉树结构的艺术馆中偷画,画都处于叶子节点处,偷画和经过走廊都需要时间,求在 ...
- codevs 访问艺术馆
/* codevs 1163 访问艺术馆 红果果的树形dp*/ #include<iostream> #include<cstdio> #include<cstring& ...
- codevs1163访问艺术馆(树形dp)
1163 访问艺术馆 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 大师 Master 题目描述 Description 皮尔是一个出了名的盗画者,他经过数月的精心准备, ...
- codevs 1163:访问艺术馆
题目描述 Description 皮尔是一个出了名的盗画者,他经过数月的精心准备,打算到艺术馆盗画.艺术馆的结构,每条走廊要么分叉为二条走廊,要么通向一个展览室.皮尔知道每个展室里藏画的数量,并且他精 ...
- 【codevs1163】访问艺术馆
题目描述 皮尔是一个出了名的盗画者,他经过数月的精心准备,打算到艺术馆盗画.艺术馆的结构,每条走廊要么分叉为二条走廊,要么通向一个展览室.皮尔知道每个展室里藏画的数量,并且他精确地测量了通过每条走廊的 ...
- 【codevs1163】访问艺术馆 树形dp
题目描述 皮尔是一个出了名的盗画者,他经过数月的精心准备,打算到艺术馆盗画.艺术馆的结构,每条走廊要么分叉为二条走廊,要么通向一个展览室.皮尔知道每个展室里藏画的数量,并且他精确地测量了通过每条走廊的 ...
- codevs1163访问艺术馆 树形dp
算裸的树形dp吧 回来复习一波 #include<cstdio> #include<cstring> #include<algorithm> #include< ...
- 2016. 4.10 NOI codevs 动态规划练习
1.codevs1040 统计单词个数 1040 统计单词个数 2001年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 De ...
随机推荐
- MIT 6.824 : Spring 2015 lab2 训练笔记
源代码参见我的github:https://github.com/YaoZengzeng/MIT-6.824 Lab 2:Primary/Backup Key/Value Service Overvi ...
- luogu1151 亲戚
题目背景 若某个家族人员过于庞大,要判断两个是否是亲戚,确实还很不容易,现在给出某个亲戚关系图,求任意给出的两个人是否具有亲戚关系. 题目描述 规定:x和y是亲戚,y和z是亲戚,那么x和z也是亲戚.如 ...
- 机器学习实战--logistic回归
#encoding:utf-8 from numpy import * def loadDataSet(): #加载数据 dataMat = []; labelMat = [] fr = open(' ...
- iOS Block 内存管理的探讨
在很多情况下Block是造成程序循环引用内存泄漏的元凶.下面我们就讲解一下block对内存管理的影响.在讲解之前.希望大家对block有一定的了解.如果大家还不是太清楚block的实现原理.希望大家可 ...
- Android中如何设置RadioButton在文字的右边,图标在左边
from:http://blog.csdn.net/sunnyfans/article/details/7901592?utm_source=tuicool&utm_medium=referr ...
- Android入门篇2-activity调用跟数据传递
一.activity调用 假设ActivityTest调用SecondActivity 1.显示调用 button1.setOnClickListener(new View.OnClickListen ...
- swift约束框架SnapKit使用
一.Swift - 自动布局库SnapKit的使用详解1(配置.使用方法.样例) 为了适应各种屏幕尺寸,iOS 6后引入了自动布局(Auto Layout)的概念,通过使用各种 Constrain ...
- HRV基础
Source: Mostly from wiki. Heart rate variability (HRV,心率变异性) is the physiological phenomenon of vari ...
- ASP.NET 单点登陆
第一种:同主域但不同子域之间实现单点登陆 Form验证其实是基于身份cookie的验证.客户登陆后,生成一个包含用户身份信息(包含一个ticket)的cookie,这个cookie的名字就是在web. ...
- 用sql查询当天,一周,一个月的数据
用sql查询当天,一周,一个月的数据 数据查询,不管在网站还是在系统,都很常见,下文是介绍最常见的以日期查询的语句 select * from ShopOrder where datediff(w ...