分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

https://www.luogu.org/problemnew/show/P1113

发布时间:2023-09-06 02:29责任编辑:沈小雨关键词:http

用DP来写,下次加拓扑

 1 #include<iostream> 2 #include<algorithm> 3 #include<cstdio> 4 #include<cstring> 5 #include<cmath> 6 #include<queue> 7 #include<stdlib.h> 8 #define mem(a) memset(a,0,sizeof(a)) 9 using namespace std;10 int f[10005];11 int main()12 {13 ??int t,n,time,u;14 ??cin>>t;15 ??int ans=0;16 ??for(int i=1;i<=t;i++)17 ??{18 ????cin>>n>>time;19 ????while((cin>>u)&&u)20 ????f[i]=max(f[i],f[u]); 21 //也可以写成 int s; s=max(f[u],s); f[i]=s+time;22 ????f[i]+=time;23 ????ans=max(f[i],ans);24 /*时时更新,f[i]改变的不是f[u],所以是不断取更高的,25 因为u<i且有无限个工人,故就算存在多个u,也是求在i时的f[i]max*/26 ??}27 ??cout<<ans<<endl;28 ??return 0;29 }
View Code

https://www.luogu.org/problemnew/show/P1113

原文地址:https://www.cnblogs.com/XXrll/p/10238140.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved