Project Euler problem 67: find maximum cost path in 100-row triangle

前端 未结 5 1159
长情又很酷
长情又很酷 2021-02-11 06:27

In Project Euler\'s problem 67 there is a triangle given and it contains 100 rows. For e.g.

        5
      9  6
    4   6  8
  0   7  1   5

I.e. 5 + 9 + 6 + 7          


        
5条回答
  •  别那么骄傲
    2021-02-11 07:17

    I believe this is a Project Euler problem.

    It can't be represented with a binary tree. Any kind of graph is overkill as well, though the problem can be solved with a longest path algorithm in directed acyclic graphs. Edit: Nevermind that, it is only useful if the edges are weighted, not the nodes.

    A two dimensional vector (e.g. vector >) is more than enough to represent such triangles, and there is a straightforward solution using such representation.

提交回复
热议问题