当前位置:网站首页>2017.10.26模拟 b energy
2017.10.26模拟 b energy
2022-08-09 06:33:00 【51CTO】
http://www.elijahqi.win/archives/1391
“`
#include
include
define N 1100
define inf 0x3f3f3f3f
include
using namespace std;
inline char gc(){
static char now[1<<16],*T,*S;
if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
return *S++;
}
inline int read(){
int x=0;char ch=getchar();
while (ch<’0’||ch>’9’) ch=getchar();
while (ch>=’0’&&ch<=’9’){x=x*10+ch-‘0’;ch=getchar();}
return x;
}
struct node{
int y,next;
}data[N];
int dp[N][110],value[N],edge[N],ans,h[N],n,num;
void dfs(int x){
if (x==0) return;
for (int i=h[x];i;i=data[i].next){
int y=data[i].y;
dfs(y);
for (int j=edge[x];j>=0;–j){
for (int j1=0;j1<=j;++j1){
dp[x][j]=max(dp[y][j1]+dp[x][j-j1],dp[x][j]);
}
}
int main(){
freopen(“energy.in”,”r”,stdin);
n=read();
for (int i=1;i<=n;++i){
int fa1=read();value[i]=read();edge[i]=read();
data[++num].y=i;data[num].next=h[fa1];h[fa1]=num;
}//memset(dp,0x3f,sizeof(dp));memset(dp[0],0,sizeof(dp[0]));
for (int i=h[0];i;i=data[i].next){
int y=data[i].y;dfs(y);
ans+=dp[y][edge[y]];
}
printf(“%d”,ans);
return 0;
}
“`
树形dp一开始写挂一波 其实 这个按照背包思想就很好写了
我枚举dp[x][j]表示x个节点我可以给j能量 然后这j个能量可以分给一号子树 二号 三号
这么多怎么办 想想飞扬的小鸟 所有的状态可以根据背包的做法只从前一个转移过来就好 就不会tle
边栏推荐
- 思维方法 解决问题的能力
- 运算放大器(OPA)超详细参数讲解-运放---以及8个型号的运算放大器分析对比
- VS2019 common shortcut keys
- ZIP压缩包文件删除密码的方法
- Xilinx Zynq ZynqMP DNA
- 直接用的zip包 缺少很多依赖,pip没有,感觉用anaconda create一个环境会方便点
- 报错:FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS重大开销和将disab补充道
- How to find package information and pin definitions for NXP S32K1xx series microcontrollers
- Web APIs BOM- 操作浏览器:本地存储
- Data center project preliminary summary
猜你喜欢

Data center project preliminary summary

Xilinx Zynq ZynqMP DNA

一道很简答但是没答对的SQL题

中英文说明书丨CalBioreagents 山羊抗人白蛋白,IgG组分

Adds, deletes, searches, and changes the leading doubly circular linked list (implemented in C language)

05 多线程与高并发 - ThreadPoolExecutor 源码解析
![[GO], arrays and slices](/img/71/86126c41d0f43aa8b9f232b219f5d7.png)
[GO], arrays and slices
![[MySQL] Second, the relationship between processes, MySQL password cracking, table building and database building related commands](/img/20/a0fb44e9360837146d0ed696c9e992.png)
[MySQL] Second, the relationship between processes, MySQL password cracking, table building and database building related commands

中英文说明书丨TRC D-阿卓糖(D-Altrose)

DevNet: Deviation Aware Networkfor Lane Detection
随机推荐
P7阿里面试题2020.07 之滑动窗算法(阿里云面试)
电学知识的疑问
MongDb的查询方式
普罗米修斯原理及节点发布
字节跳动面试题之镜像二叉树2020
按图搜索1688商品接口(item_search_img-按图搜索1688商品(拍立淘接口)代码对接教程
报错:flask: TypeError: ‘function‘ object is not iterable
e-learning summary
untiy countdown
VS2019常用快捷键
中英文说明书丨TRC D-阿卓糖(D-Altrose)
pycharm环境包导入到另外一个环境
移远EC20 4G模块拨号相关
Unity backgammon game design and simple AI implementation (1)
SIGINT,SIGKILL,SIGTERM信号区别,各类信号总结
线程池总结
Altium designer software commonly used the most complete package library, including schematic library, PCB library and 3D model library
How to find package information and pin definitions for NXP S32K1xx series microcontrollers
[R language] Extract all files under a folder to a specific folder
ZIP压缩包文件删除密码的方法