当前位置:网站首页>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
边栏推荐
猜你喜欢
Fragments
【Feel】In the Unity Feel plugin, Camera cannot display CameraShake correctly
Unity C# 委托——事件,Action,Func的作用和区别
CalBioreagents超全Id 蛋白兔单克隆抗体,助力科研
jvm线程状态
Unity Gobang Game Design and Simple AI (2)
Data center project preliminary summary
Flask failed to create database without error
Xilinx Zynq ZynqMP DNA
Error jinja2.exceptions.UndefinedError: 'form' is undefined
随机推荐
2022-08-08: Given an array arr, it represents the height of the missiles that will appear in order from morning to night.When the cannon shoots missiles, once the cannon is set to shoot at a certain h
Unity五子棋游戏设计 和简单AI实现(1)
The singleton pattern
Unity Gobang Game Design and Simple AI(3)
Unity Gobang Game Design and Simple AI (2)
治疗消化性溃疡—Toronto Research Chemicals 甘氨酸铝
io.lettuce.core。RedisCommandTimeoutException命令超时
jvm线程状态
默默重新开始,第一页也是新的一页
工控设备的系统如何进行加固
shardingsphere数据分片配置项说明和示例
安装flask
Gao Zelong, a famous digital collection expert and founder of the Digital Collection Conference, was interviewed by China Entrepreneur Magazine
Flask failed to create database without error
The division principle summary within the collection
ZIP压缩包文件删除密码的方法
集合内之部原理总结
报错jinja2.exceptions.UndefinedError: ‘form‘ is undefined
报错:FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS重大开销和将disab补充道
Altium designer software commonly used the most complete package library, including schematic library, PCB library and 3D model library