贪心算法每一步选择局部最优解,最终可以得到全局最优解
贪心算法有时是一种近似算法,如对于背包问题有可能得到的不是最优解,但是十分接近
集合覆盖问题代码:
package chapter8;
import java.util.*;
public class Boardcast {
public static String findBiggest (HashSet<String> needed, HashMap<String, String[]> station) {
LinkedList<String> result = new LinkedList<String>();
Set<String> stations = station.keySet();
HashMap<String, Integer> stateContained = new HashMap<String, Integer>();
//find the best one according to the states it covers
for (String boardcast : stations)