当前位置:网站首页>Luogu p1073 [noip2009 improvement group] optimal trade (layered diagram + shortest path)

Luogu p1073 [noip2009 improvement group] optimal trade (layered diagram + shortest path)

2022-06-25 08:02:00 Mfy's little brother 1

Luogu P1073 [NOIP2009 Improvement group ] The best trade ( Hierarchical graph + shortest path )

The question :

Digraph with point weight , The point weight of each point represents , The price at which the crystal ball is purchased or sold . Seek from 1 To n, Choose to buy crystal balls at one point , Then choose the maximum profit after selling the crystal ball at one point . A point can pass many times .

Ideas :

Method 1 : Shrinkage point +dp( A topological sort )

Method 2 : Hierarchical graph + shortest path :

picture source
 Insert picture description here

The edge weight of each layer is 0, The weights connecting the points of the first layer to the points of the second layer are negative numbers of point weights , Means to buy at this point , The weight of the points connecting the second layer to the third layer is a positive number of the point weight , Means sell at this point

Because you have negative power , Can only run spfa

原网站

版权声明
本文为[Mfy's little brother 1]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206250624540035.html