Where have we implemented a greedy algorithm, or have been asked to do a greedy algorithm? Well, there are not that many things you guys have been working on this semester.
现在你已经实施了一个贪婪算法,我们在哪里实施了贪婪算法,或者我们那里被要求实施贪婪算法呢?,们这学期不需要用什么功对吧?
But let's look for a slight variant of it, where greedy is not so good. And that's what's called the zero-one knapsack problem.
但是让我们找一找它的一些变种,在这些变种中贪婪算法用处不大,这些问题也就是0/1背包问题。
In order to fill their own bellies, so greedy are they, they intruded into the church's fold and devour for themselves -this is how the allegory works -devour for themselves the nourishment that of course they should be sharing with their flock.
为了填满他们的欲望,他们挥霍了教会的资金,这就是讽喻的含义,在自我满足中尽情的挥霍,当然他们需要与自己的信徒共享。
What do you get if you follow the greedy algorithm? What's the first thing the thief does?
如果年贪婪算法你会带走什么呢?,这个贼做的第一件事是什么?
We'll start with the greedy thief. Well, the greedy thief follows the greedy algorithm.
我们从贪婪的贼开始,这个贪婪的贼按贪婪算法行动。
There's no more room. So the greedy thief take that and leaves.
所以这个贪婪的贼就带着这些东西走了,但是这并不是一个最优选择。
with the continuous knapsack problem as we've formulated it, greedy is good.
因为正如我们已经归越过的,对于一般连续性背包问题贪婪算法很实用。
So he's packing and unpacking, packing and unpacking, trying all possible combinations of objects that will obey the constraint. And then choosing the winner. Well, this is like an algorithm we've seen before. It's not greedy.
因此它不断装包和清包,尝试了所有满足约束条件的物品组合,最后选择最优者,这很像我们以前看过的一个算法,这不是贪婪算法。
Instead of taking that one vase, the thief could take two radios. And get more value. So the greedy thief, in some sense, gets the wrong answer. But maybe isn't so dumb.
这个贼可以带走两个收音机,这样总价值更大,因此这个贪婪的贼,在某种意义上没有得到正确的答案,但是可能它也不笨。
应用推荐