当前位置: 首页 > 工具软件 > algo-coin > 使用案例 >

greedy(meta-algo III)

夹谷成龙
2023-12-01

Every two years old knows the greedy algorithm.

In order to get what you want, just start grabbing what looks best.

Surprisingly, many important and practical computational problems can be solved this way.

Ingredients:

the possible inputs to the problem.

each instance has an exponentially large set of solutions.

the brute force algorithm:

try every solution! exponentially time, because exponentially many.

The greedy choice:

commit to the object that looks the best.

must prove that this locally greedy choice does not have negative global consequences.

but greedy algorithms do not try to predict the future and do not back track.

 

problem: find the minimum # of 4,3, and 1 cent coins to make up 6 cents.

Greedy choice: start by grabbing a 4 coin.

consequences:

4 +1 +1 =6  mistake

3 +3 better

greedy algorithm does not work.

 

greedy algorithm : easy to understand and to code, but do they work?

for most optimization problems, all greedy problems tried do not work.

a few have greedy algorithms, the proof that they work, however, is subtle.

loop invariant:

recall that a loop invariant makes a statement each time the algorithm is at the top of the loop about what it has accomplished.

after the algorithm has committed to one object, what statement do we want to make about this action?

the algorithm's solution is optimal.

The algorithm has only committed to one object and this does not constitute a valid solution.

what the algorithm has done so far is optimal.

being optimal is a property of full solutions.

"more of the input", this kind of loop invariant is hard to extend from partial instances to full instances.

It is ok to burn a few of your bridges as long as you do not burn all of them. :)

...

but, this way only for the first iteration. :(

St extends At

 If At makes a decision about an object, the St makes the same decision.

 What other decisions St makes is unknown to the algorithm and to the prover.

So,

in the t+1 th time steps, the algorithm A(t+1)decides about the next "best" object.

Stextends A(t+1). !!!

This "bridge" has been burned!

loop invariant:

we have not gone wrong.

there is at least one optimal solution St+1 that extends the choices At+1 made so far.

if there are no optimal solutions that extends the choices made so far, we went wrong.

 Schedule problem:

greedy criteria: earliest finishing time

motivation: schedule the event which will free up your room for someone else as soon as possible.

 

 

转载于:https://www.cnblogs.com/grep/archive/2012/05/13/2497934.html

 类似资料: