且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

需要帮助与算法找到DAG中的最大路径

更新时间:2023-11-24 08:35:46

我会用 int s。

从底部一行开始,比较每个被分配的数字对。取较大的一个,并将其添加到对上方的数字:

Start at the bottom row and compare each adjanced pair of numbers. Take the bigger one and add it to the number above the pair:

 5 3             13  3
  \
7 8 6  becomes  7  8  6
^ ^

                  13 3               13 11
                     /
Next iteration   7  8  6   becomes  7  8  6  etc.
                    ^  ^

以你的方式到顶部,当你完成后,将包含最大的金额。

Work your way to the top and when you're done, the tip of the triangle will contain the largest sum.