Hi,

I haven't tried with your example, but this article might help you for dynamic programming:
[link:laurent.le-brun.eu]

Another technique useful for dynamic programming is the use of an array with lazy values. I'll try with your example later.

Laurent.

By on 3/8/2008 3:38 AM ()

You can compute the length matrix (called "c" in the book) in this way:

1
2
3
4
5
6
let X = [|'B'; 'D'; 'C'; 'A'; 'B'; 'A'|]
let Y = [|'A'; 'B'; 'C'; 'B'; 'D'; 'A'; 'B'|]
let rec store = Array2.init (X.Length+1) (Y.Length+1) <| fun i j ->
  lazy if i = 0 || j = 0 then 0
       elif X.[i-1] = Y.[j-1] then store.[i-1, j-1].Force() + 1
       else max <| store.[i, j-1].Force() <| store.[i-1, j].Force()

And then, print it:

1
store |> Array2.map (fun x -> x.Force()) |> print_any
By on 3/8/2008 7:09 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper