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】访问艺术馆的更多相关文章

  1. codevs 1163 访问艺术馆

    1163 访问艺术馆  时间限制: 1 s  空间限制: 128000 KB       题目描述 Description 皮尔是一个出了名的盗画者,他经过数月的精心准备,打算到艺术馆盗画.艺术馆的结 ...

  2. Codevs No.1163 访问艺术馆

    2016-05-31 20:48:47 题目链接: 访问艺术馆 (Codevs No.1163) 题目大意: 一个贼要在一个二叉树结构的艺术馆中偷画,画都处于叶子节点处,偷画和经过走廊都需要时间,求在 ...

  3. codevs 访问艺术馆

    /* codevs 1163 访问艺术馆 红果果的树形dp*/ #include<iostream> #include<cstdio> #include<cstring& ...

  4. codevs1163访问艺术馆(树形dp)

    1163 访问艺术馆  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 大师 Master   题目描述 Description 皮尔是一个出了名的盗画者,他经过数月的精心准备, ...

  5. codevs 1163:访问艺术馆

    题目描述 Description 皮尔是一个出了名的盗画者,他经过数月的精心准备,打算到艺术馆盗画.艺术馆的结构,每条走廊要么分叉为二条走廊,要么通向一个展览室.皮尔知道每个展室里藏画的数量,并且他精 ...

  6. 【codevs1163】访问艺术馆

    题目描述 皮尔是一个出了名的盗画者,他经过数月的精心准备,打算到艺术馆盗画.艺术馆的结构,每条走廊要么分叉为二条走廊,要么通向一个展览室.皮尔知道每个展室里藏画的数量,并且他精确地测量了通过每条走廊的 ...

  7. 【codevs1163】访问艺术馆 树形dp

    题目描述 皮尔是一个出了名的盗画者,他经过数月的精心准备,打算到艺术馆盗画.艺术馆的结构,每条走廊要么分叉为二条走廊,要么通向一个展览室.皮尔知道每个展室里藏画的数量,并且他精确地测量了通过每条走廊的 ...

  8. codevs1163访问艺术馆 树形dp

    算裸的树形dp吧 回来复习一波 #include<cstdio> #include<cstring> #include<algorithm> #include< ...

  9. 2016. 4.10 NOI codevs 动态规划练习

    1.codevs1040 统计单词个数 1040 统计单词个数 2001年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题目描述 De ...

随机推荐

  1. Activity的onCreate()的PersistableBundle 参数坑。

    Bundle 与 PersistableBundle 区别 仅仅是Activity oncreate()的一个参数与两个参数的区别: @Override public void onCreate(Bu ...

  2. CF722C. Destroying Array[并查集 离线]

    链接:Destroying Array C. Destroying Array time limit per test 1 second memory limit per test 256 megab ...

  3. BZOJ1216[HNOI2003]操作系统 [模拟 优选队列]

    1216: [HNOI2003]操作系统 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 754  Solved: 421[Submit][Status ...

  4. 第5章 绘图基础_5.1-5.4 GDI绘图

    5.1 GDI的原理和结构 (1)提供一种特殊机制彻底隔离应用程序与不同输出设备(eg.显示器或打印机),以便支持 与设备无关的图形. 光栅设备(如显示器.激光打印机):图像是由点构成的矩阵 图形输出 ...

  5. jquery无缝间歇向上滚动(间断滚动)

    jquery无缝间歇向上滚动 JS部份 $(function(){ var $this = $(".renav"); var scrollTimer; $this.hover(fu ...

  6. Centos6.2 下 vncserver 的安装

    好久没用vnc了, 把今天装的过程记录一下, 这是一个从网上下载的标准Centos6.2 虚机镜像, 已经带了桌面. 默认的用户是root和tom, 口令都是tomtom. 因为ssh服务没起来, 简 ...

  7. VS2013使用EF6与mysql数据库

      您的项目引用了最新实体框架:但是,找不到数据链接所需的与版本兼容的实体框架数据库 EF6使用Mysql的技巧   在vs2013中使用mysql连接entityFramework经常会遇到这个问题 ...

  8. 将数据库备份到AZURE blob storage

    1创建一个Storage Account 1)点击Browse->Storage accounts 2) 填写Storage account,请记住这个名字,之后创建credential需要用到 ...

  9. eval的对于验证数学公式的用处

    var a=10,b=20; var s=a+b+((a/b)+(a+(a-b)))+(11)/a; var r=eval(s); console.log(r); 只要不报错,说明公式正确, 报错公式 ...

  10. java JAXB 学习

    JAXB(Java Architecture for XML Binding)是JDK的一部分,用于Object <-> XML的转换(有点类似于.NET中的XML序列化). 1.创建XS ...