博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
codevs1163访问艺术馆 树形dp
阅读量:7029 次
发布时间:2019-06-28

本文共 1198 字,大约阅读时间需要 3 分钟。

算裸的树形dp吧 回来复习一波

#include
#include
#include
#include
using namespace std;const int M=1007;int read(){ int ans=0,f=1,c=getchar(); while(c<'0'||c>'9'){
if(c=='-') f=-1; c=getchar();} while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();} return ans*f;}int tot,cnt=1,k;int f[M][1005];struct node{
int w,v,l,r;}tr[M];void dfs(int x){ tr[x].v=read(); k=read(); cnt++; if(!k){ tr[x].l=cnt; dfs(tr[x].l); tr[x].r=cnt; dfs(tr[x].r); }else tr[x].w=k;}void trdp(int x){ if(!tr[x].l&&!tr[x].r){ for(int i=2*tr[x].v;i<=tot;i++){ int now=(i-2*tr[x].v)/5; if(now<=tr[x].w) f[x][i]=now; else f[x][i]=tr[x].w; } return ; } if(tr[x].l) trdp(tr[x].l); if(tr[x].r) trdp(tr[x].r); for(int i=2*tr[x].v;i<=tot;i++){ int l=tr[x].l,r=tr[x].r; for(int j=0;j<=i-(2*tr[x].v);j++) f[x][i]=max(f[x][i],f[l][j]+f[r][i-(2*tr[x].v)-j]); }}int main(){ tot=read(); dfs(1); trdp(1); printf("%d\n",f[1][tot]); return 0;}
View Code

 

转载于:https://www.cnblogs.com/lyzuikeai/p/7086838.html

你可能感兴趣的文章
高度自适应,内容是浮动元素
查看>>
201671010128 2016-2017-2 《Java程序设计》之Java的基本程序设计结构
查看>>
存储前set方法相互关联 只关联了一方 分别set
查看>>
3.3 类中常用特殊装饰器
查看>>
Redis 安装
查看>>
HDU 1495 非常可乐
查看>>
Sqlite3+EF6踩的坑
查看>>
【tyvj1860】后缀数组
查看>>
Java多线程(九)之ReentrantLock与Condition
查看>>
Spring源码剖析依赖注入实现
查看>>
使用Spring Cloud Feign作为HTTP客户端调用远程HTTP服务
查看>>
第九次作业 160809309 朱庆海
查看>>
对百度WebUploader的二次封装,精简前端代码之图片预览上传(两句代码搞定上传)...
查看>>
【leetcode】18 4 sum
查看>>
fiddler工具的使用
查看>>
jquery源码分析(二)——架构设计
查看>>
bzoj1935 [SHOI2007]Tree 园丁的烦恼
查看>>
javascript深入理解js闭包(转)
查看>>
207. Course Schedule
查看>>
如何优化您的 Android 应用 (Go 版)
查看>>