当前位置:网站首页>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
边栏推荐
- 【R语言】对文件进行归一化整理到各文件类型文件夹
- [HNOI2002]营业额统计
- 输入框最前面添加放大镜&&background-image和background-color冲突问题
- 如何 认识与学习BASH
- 中英文说明书丨CalBioreagents ACTH N端单克隆抗体
- 直接用的zip包 缺少很多依赖,pip没有,感觉用anaconda create一个环境会方便点
- P6阿里机试题之2020 斐波那契数
- 报错jinja2.exceptions.UndefinedError: ‘form‘ is undefined
- Simple Factory Pattern
- Output method of list string print(*a) print(““.join(str(c) for c in a) )
猜你喜欢
Word文件的只读模式没有密码怎么退出?
中英文说明书丨CalBioreagents 醛固酮单克隆抗体
Search 1688 product interface by image (item_search_img-search 1688 product by image (Politao interface) code docking tutorial
Integer 线程安全的
Xilinx Zynq ZynqMP DNA
GNNExplainer applied to node classification task
[MySQL] Second, the relationship between processes, MySQL password cracking, table building and database building related commands
How to find package information and pin definitions for NXP S32K1xx series microcontrollers
workbench 数据导出
报错:FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disab
随机推荐
常用Oracle命令
什么是excel文件保护
The solution that does not work and does not take effect after VScode installs ESlint
变压器的工作原理(图解,原理图讲解,一看就懂)
Unity五子棋游戏设计 和简单AI实现(1)
install flask
线程池总结
workbench 数据导出
db.sqlite3没有“as Data Source“解决方法
jvm线程状态
Teach you how to make the Tanabata meteor shower in C language - elegant and timeless (detailed tutorial)
代码目录结构
el-table缓存数据
flask创建数据库失败未报错
输入框最前面添加放大镜&&background-image和background-color冲突问题
Introduction and use of BeautifulSoup4
e-learning summary
移远EC20 4G模块拨号相关
字节跳动笔试题2020 (抖音电商)
【Wwise】ArgumentException: The specified path is not of a legal form (empty). About the path reading error in WwiseGlobal