How to solve this dynamic programming problem with haskell ?

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.

Osager Prairie wrote:
I saw this problem from Topcoder I understand that it can be solved with dynamic programming with a bottom-up approach.
The following introduction to dynamic programming in Haskell may help http://www.chneukirchen.org/repos/blogcode/dynprog-haskell.pdf More generally, the key is to realize that dynamic programming follows directly from memoization. Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com
participants (2)
-
Heinrich Apfelmus
-
Osager Prairie