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. [No00005D]如何高效利用GitHub

    原文地址:http://www.yangzhiping.com/tech/github.html 正是Github,让社会化编程成为现实.本文尝试谈谈GitHub的文化.技巧与影响. Q1:GitHu ...

  2. 转:[版本控管]TortoiseSVN 使用,抓出兇手,使用 Blame 查看每一行最後修改的人是誰

    类似的官方的使用手段有: https://tortoisesvn.net/docs/nightly/TortoiseSVN_zh_CN/tsvn-dug-blame.html from: http:/ ...

  3. nginx的主要用途

    1.反向代理加速(无缓存),简单的负载均衡和容错  : 问题一:为什么反向代理可以做加速服务器? 反向代理接受发给web服务器的真实请求,但与web服务器不同的是,它们可以向其他的服务器进行通信.以便 ...

  4. BZOJ 2818: Gcd

    2818: Gcd Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 4443  Solved: 1960[Submit][Status][Discuss ...

  5. 让树莓派开机发送自己的ip到邮箱

    一.代码如下: sendIpMail.py #-*-coding=utf-8-*- import socket import fcntl import struct from email import ...

  6. iOS关于html缓存

    方式一:截取请求正则.图片缓存 实现webview缓存网页内容难点在缓存图片上.html代码的缓存相对简单,具体实现思路是这样的:第1步.先获取html页面里所有图片地址.方法一:离线获取获取到htm ...

  7. 10 Things Every Java Programmer Should Know about String

    String in Java is very special class and most frequently used class as well. There are lot many thin ...

  8. 在SharePoint列表中使用自增栏

    问:sps2010里能不能新建个栏,数字型的,自动加一 答:在SharePoint里,有很多方法可以实现一个自增栏.在这里,我将介绍其中两种方式. 1.计算栏 2.列表项事件接收器 1.采用计算栏来实 ...

  9. swift邮箱手机验证

    import UIKit class Validate: NSObject { //邮箱.手机验证 enum ValidatedType { case Email case PhoneNumber } ...

  10. 分布式中使用Redis实现Session共享(一)

    上一篇介绍了如何使用nginx+iis部署一个简单的分布式系统,文章结尾留下了几个问题,其中一个是"如何解决多站点下Session共享".这篇文章将会介绍如何使用Redis,下一篇 ...