-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuyCount.fsx
More file actions
33 lines (29 loc) · 1.44 KB
/
buyCount.fsx
File metadata and controls
33 lines (29 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
open System.Collections.Generic
let buyCount totalCost items =
let memo = Dictionary()
let rec buyCount totalCost items =
match memo.TryGetValue((totalCost, items)) with
| true, result -> result
| false, _ ->
let result =
match sign totalCost, items with
| 0, _ -> Some []
| -1, _ | _, [] -> None
| _ , (name, cost)::rest->
[[name, cost], totalCost - cost; [], totalCost]
|> List.choose (fun (item, nextCost) -> buyCount nextCost rest |> Option.map (List.append item))
|> function [] -> None | results -> results |> List.maxBy List.length |> Some
memo.Add((totalCost, items), result)
result
buyCount totalCost items
let items = [
("USP", 500); ("Glock", 400); ("P229", 600); ("DesertEagle", 650); ("FiveseveN", 750);
("Beretta", 800); ("M3", 1700); ("M1014", 3000); ("TMP", 1250); ("Mac10", 1400);
("MP5", 1500); ("UMP", 1700); ("P90", 2350); ("Galil", 2000); ("FAMAS", 2250);
("AK47", 2500); ("M4A1", 3100); ("AUG", 3500); ("SG552", 3500); ("Scout", 2750);
("SG550", 4200); ("G3SG1", 5000); ("AWP", 4750); ("M249", 5750); ("HEGrenade", 300);
("Flashbang", 200); ("SmokeGrenade", 300); ("Vest", 650); ("Helmet", 350); ("Shield", 2200);
("DefuseKit", 200); ("NightVision", 1250)]
//目標金額
let totalCost = 16000
buyCount totalCost items