CF1083A The Fair Nut and the Best Path(树形dp)

给定一棵包含 n 个结点的树,树上的每个结点拥有点权 wi,每一条边拥有边权 ci

你可以从树的某个结点出发,沿着树边通往一个未曾经过的结点。每当你到达一个新的结点(包括起点)时,你能获得该结点点权的收益,同时,每经过一条树边,你都会损失该条边边权的收益。

你需要规划出一条路径,使得你在沿着该路径行进的任意时刻收益值均非负,且行进结束时的收益值应尽可能大。输出结束时的最大收益值。

dp[x][0]表示以x作为路径的两端点时的最优解,dp[x][1]表示以x作为路径中点时的最优解

那么由于每个点只能访问一次,中点的dp值就从最大的zhong儿子和次大的儿子转移过来,终点的dp值只能从最大的儿子处转移过来

为了控制路径收益时刻大于0,把最大值和次大值初值设定为0即可

代码:

#include <bits/stdc++.h>
#define int long long
#define sc(a) scanf("%lld",&a)
#define scc(a,b) scanf("%lld %lld",&a,&b)
#define sccc(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define schar(a) scanf("%c",&a)
#define pr(a) printf("%lld",a)
#define fo(i,a,b) for(int i=a;i<b;++i)
#define re(i,a,b) for(int i=a;i<=b;++i)
#define rfo(i,a,b) for(int i=a;i>b;--i)
#define rre(i,a,b) for(int i=a;i>=b;--i)
#define prn() printf("\n")
#define prs() printf(" ")
#define mkp make_pair
#define pii pair<int,int>
#define pub(a) push_back(a)
#define pob() pop_back()
#define puf(a) push_front(a)
#define pof() pop_front()
#define fst first
#define snd second
#define frt front()
#define bak back()
#define mem0(a) memset(a,0,sizeof(a))
#define memmx(a) memset(a,0x3f3f,sizeof(a))
#define memmn(a) memset(a,-0x3f3f,sizeof(a))
#define debug
#define db double
#define yyes cout<<"YES"<<endl;
#define nno cout<<"NO"<<endl;
using namespace std;
typedef vector<int> vei;
typedef vector<pii> vep;
typedef map<int,int> mpii;
typedef map<char,int> mpci;
typedef map<string,int> mpsi;
typedef deque<int> deqi;
typedef deque<char> deqc;
typedef priority_queue<int> mxpq;
typedef priority_queue<int,vector<int>,greater<int> > mnpq;
typedef priority_queue<pii> mxpqii;
typedef priority_queue<pii,vector<pii>,greater<pii> > mnpqii;
const int maxn=500005;
const int inf=0x3f3f3f3f3f3f3f3f;
const int MOD=100000007;
const db eps=1e-10;
int qpow(int a,int b){int tmp=a%MOD,ans=1;while(b){if(b&1){ans*=tmp,ans%=MOD;}tmp*=tmp,tmp%=MOD,b>>=1;}return ans;}
int lowbit(int x){return x&-x;}
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
int mmax(int a,int b,int c){return max(a,max(b,c));}
int mmin(int a,int b,int c){return min(a,min(b,c));}
void mod(int &a){a+=MOD;a%=MOD;}
bool chk(int now){}
int half(int l,int r){while(l<=r){int m=(l+r)/2;if(chk(m))r=m-1;else l=m+1;}return l;}
int ll(int p){return p<<1;}
int rr(int p){return p<<1|1;}
int mm(int l,int r){return (l+r)/2;}
int lg(int x){if(x==0) return 1;return (int)log2(x)+1;}
bool smleql(db a,db b){if(a<b||fabs(a-b)<=eps)return true;return false;}
db len(db a,db b,db c,db d){return sqrt((a-c)*(a-c)+(b-d)*(b-d));}
bool isp(int x){if(x==1)return false;if(x==2)return true;for(int i=2;i*i<=x;++i)if(x%i==0)return false;return true;}
inline int read()
{
    char ch=getchar();int s=0,w=1;
    while(ch<48||ch>57){if(ch=='-')w=-1;ch=getchar();}
    while(ch>=48&&ch<=57){s=(s<<1)+(s<<3)+ch-48;ch=getchar();}
    return s*w;
}
inline void write(int x)
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)write(x/10);
    putchar(x%10+48);
}

int n,w[maxn],x,y,z,ans=0;
vei e[maxn],v[maxn];
int dp[maxn][2];

void dfs(int x,int f){
    int mx1=0,mx2=0;
    fo(i,0,e[x].size()){
        int y=e[x][i];
        if(y==f) continue;
        dfs(y,x);
        if(dp[y][0]-v[x][i]>=mx1){
            mx2=mx1;
            mx1=dp[y][0]-v[x][i];
        }
        else if(dp[y][0]-v[x][i]>mx2)
            mx2=dp[y][0]-v[x][i];
    }
    dp[x][0]=mx1+w[x];
    dp[x][1]=mx1+mx2+w[x];
    ans=mmax(ans,dp[x][0],dp[x][1]);
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>n;
    re(i,1,n) cin>>w[i];
    re(i,1,n-1){
        cin>>x>>y>>z;
        e[x].pub(y);
        v[x].pub(z);
        e[y].pub(x);
        v[y].pub(z);
    }
    dfs(1,1);
    cout<<ans<<endl;
    return 0;
}

 

转载于:https://www.cnblogs.com/oneman233/p/11493222.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
目标检测(Object Detection)是计算机视觉领域的一个核心问题,其主要任务是找出图像中所有感兴趣的目标(物体),并确定它们的类别和位置。以下是对目标检测的详细阐述: 一、基本概念 目标检测的任务是解决“在哪里?是什么?”的问题,即定位出图像中目标的位置并识别出目标的类别。由于各类物体具有不同的外观、形状和姿态,加上成像时光照、遮挡等因素的干扰,目标检测一直是计算机视觉领域最具挑战性的任务之一。 二、核心问题 目标检测涉及以下几个核心问题: 分类问题:判断图像中的目标属于哪个类别。 定位问题:确定目标在图像中的具体位置。 大小问题:目标可能具有不同的大小。 形状问题:目标可能具有不同的形状。 三、算法分类 基于深度学习的目标检测算法主要分为两大类: Two-stage算法:先进行区域生成(Region Proposal),生成有可能包含待检物体的预选框(Region Proposal),再通过卷积神经网络进行样本分类。常见的Two-stage算法包括R-CNN、Fast R-CNN、Faster R-CNN等。 One-stage算法:不用生成区域提议,直接在网络中提取特征来预测物体分类和位置。常见的One-stage算法包括YOLO系列(YOLOv1、YOLOv2、YOLOv3、YOLOv4、YOLOv5等)、SSD和RetinaNet等。 四、算法原理 以YOLO系列为例,YOLO将目标检测视为回归问题,将输入图像一次性划分为多个区域,直接在输出层预测边界框和类别概率。YOLO采用卷积网络来提取特征,使用全连接层来得到预测值。其网络结构通常包含多个卷积层和全连接层,通过卷积层提取图像特征,通过全连接层输出预测结果。 五、应用领域 目标检测技术已经广泛应用于各个领域,为人们的生活带来了极大的便利。以下是一些主要的应用领域: 安全监控:在商场、银行
To find the tensile capacity P1 for the single-shear lap connection, we need to calculate the strength of the bolts and the strength of the plate. Strength of Bolts: The ultimate strength of the bolts is determined by the minimum of the following: 1. Bolt shear strength 2. Bolt bearing strength 3. Bolt tensile strength Bolt Shear Strength: The bolt shear strength is given by: Vn = 0.6*Fy*Ab where Vn is the nominal shear strength of the bolt, Fy is the yield strength of the bolt material, and Ab is the cross-sectional area of the bolt. Substituting the given values, we get: Vn = 0.6*90*0.44 = 23.76 kips Bolt Bearing Strength: The bolt bearing strength is given by: Rn = 2.4*dt*t*Fyb where Rn is the nominal bearing strength of the bolt, dt is the thickness of the connected material, t is the thickness of the bolt head or nut, and Fyb is the yield strength of the bolt material. Substituting the given values, we get: Rn = 2.4*0.75*0.75*90 = 121.5 kips Bolt Tensile Strength: The bolt tensile strength is given by: Tn = 0.75*Fub*Ab where Tn is the nominal tensile strength of the bolt, Fub is the ultimate strength of the bolt material, and Ab is the cross-sectional area of the bolt. Substituting the given values, we get: Tn = 0.75*120*0.44 = 29.7 kips The minimum of the above three values is the ultimate strength of the bolt, which is 23.76 kips. Strength of Plate: The ultimate strength of the plate is determined by the minimum of the following: 1. Plate tensile strength 2. Plate bearing strength 3. Plate yielding strength Plate Tensile Strength: The plate tensile strength is given by: Pu = Fu*Ap where Pu is the ultimate strength of the plate, Fu is the ultimate strength of the plate material, and Ap is the effective net area of the plate. The effective net area of the plate is given by: Ap = An - n*d*(dh + 0.5*t) where An is the gross area of the plate, n is the number of bolts, d is the bolt diameter, dh is the diameter of the hole, and t is the thickness of the connected material. Substituting the given values, we get: An = 12*1 = 12 in² n = 4 d = 0.75 in dh = 0.8125 in (assuming 1/16 in oversize hole) t = 1 in Ap = 12 - 4*0.75*(0.8125 + 0.5*1) = 5.25 in² Substituting the given values, we get: Pu = 58*5.25 = 304.5 kips Plate Bearing Strength: The plate bearing strength is given by: Rn = 2.4*dt*t*Fyb where Rn is the nominal bearing strength of the plate, dt is the thickness of the connected material, t is the thickness of the bolt head or nut, and Fyb is the yield strength of the bolt material. Substituting the given values, we get: Rn = 2.4*1*0.75*36 = 64.8 kips Plate Yielding Strength: The plate yielding strength is given by: Py = 0.9*Fy*Ag where Py is the yielding strength of the plate, Fy is the yield strength of the plate material, and Ag is the gross area of the plate. Substituting the given values, we get: Ag = 12*1 = 12 in² Py = 0.9*36*12 = 388.8 kips The minimum of the above three values is the ultimate strength of the plate, which is 64.8 kips. Now, we can find the tensile capacity P1 of the connection by taking the minimum of the ultimate strength of the bolts and the ultimate strength of the plate. P1 = min(23.76, 64.8) = 23.76 kips Therefore, the tensile capacity P1 for the single-shear lap connection is 23.76 kips.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值