Skip to content

Instantly share code, notes, and snippets.

@adilakhter
Last active December 13, 2015 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adilakhter/4968644 to your computer and use it in GitHub Desktop.
Save adilakhter/4968644 to your computer and use it in GitHub Desktop.
let computeOptPartySchedule (budget,N,(costs:int[]),(funValues:int[])) =
let OPT = Array2D.zeroCreate (N+1) (budget+1)
for i = 1 to N do
for j = 0 to budget do
let c_i = costs.[i-1] //cost for the ith party
let f_i = funValues.[i-1] // fun value associated with ith party
OPT.[i,j] <-
match j,c_i with
| _ when j<c_i -> OPT.[i-1,j]
| _ -> Math.Max(OPT.[i-1,j],f_i + OPT.[i-1, j-c_i])
// returning (1) summation of all entrance fee or costs,
// (2) summation of fun values
((budget,N,OPT,OPT.[N,budget])|>computeOptCost, OPT.[N,budget])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment