题目内容
As a burgler robs a house, she finds the following items:Dirt - Weight: 4, Value: 0Computer - Weight: 10, Value: 30Fork - Weight: 5, Value: 1Problem Set - Weight: 0, Value: -10This time, she can only carry a weight of 14, and wishes to maximize the value to weight ratio of the things she carries. She employs three different metrics in an attempt to do this, and writes an algorithm in Python to determine which loot to take.The algorithm works as follows:Evaluate the metric of each item. Each metric returns a numerical value for each item.For each item, from highest metric value to lowest, add the item if there is room in the bag.Describe the heuristic that each of the following 3 metrics uses, and choose the result of running the algorithm with each metric.Metric 1:def metric1(item): return item.getValue() / float(item.getWeight()) # We want exact values!Which heuristic does Metric 1 employ?
查看答案
搜索结果不匹配?点我反馈
更多问题