От: | Пельмешко | blog | |
Дата: | 06.02.10 10:58 | ||
Оценка: | 2 (1) |
type Color = Red | Black
let memoize f =
let dict = System.Collections.Generic.Dictionary()
fun x -> match dict.TryGetValue(x) with
| false, __ -> let t = f x in dict.Add(x,t); t
| true, res -> res
let solve len =
let rec brute = memoize <| fun (color, len) ->
let color', min =
match color with Red -> Black, 1I
| Black -> Red, 3I
let rec loop l c =
if (l = 0I) then c + 1I
else loop (l-1I) (c + brute (color', l))
let x = len - min
if (x < 0I) then 0I else loop x 0I
brute (Black, len) + brute (Red, len)
This and other recursive references to the object(s) being defined will be checked for initialization-soundness at runtime through the use of a delayed reference. This is because you are defining one or more recursive objects, rather than recursive functions. This warning may be suppressed by using #nowarn "40" or --nowarn 40.