[Haskell-beginners] How to solve this dynamic programming problem with haskell ?

Osager Prairie osagerprairie at gmail.com
Fri Mar 2 14:28:19 CET 2012


Hi all:
I saw this problem from Topcoder
I understand that it can be solved with dynamic programming with a
bottom-up approach.

But I really don't know how to implement it in Haskell.

Could anyone help me out ?

For the moment my haskell muscle only allows me to solve some naive list
processing problems. I really need to strengthen up.

Thanks in advance

Problem Statement
         The Casket of Star (sic) is a device in the Touhou universe. Its
purpose is to generate energy rapidly. Initially it contains n stars in a
row. The stars are labeled 0 through n-1 from the left to the right. You
are given a int[] weight, where weight[i] is the weight of star i.


The following operation can be repeatedly used to generate energy:

     Choose a star x other than the very first star and the very last star.
     The x-th star disappears.
     This generates weight[x-1] * weight[x+1] units of energy.
     We decrease n and relabel the stars 0 through n-1 from the left to the
right.

Your task is to use the device to generate as many units of energy as
possible. Return the largest possible total amount of generated energy.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120302/75d96b1f/attachment.htm>


More information about the Beginners mailing list