2

我正在编写一个蛮力算法来解决这样的顶点覆盖:

BruteForceVertexCover( Graph G = (V,E) ){
    for size= 1 ... |V|
        vector<int> v = {0...size-1}
        do{
            if(test(G, v)) return v;     //test if v covers G
        }
        while(v has next combinations of lenght size);
    return empty vector<int>;
}

//this stops when find a answer, and it will find,
//since it tries all combinations of all sizes

在哪里

bool test( Graph G = (V,E), vector<int> v ){
    for each u in v:
        for each w in G[u]
            remove u from G[w]     //this is linear in size of vector G[w]
        clear G[v]                 //removed all (bidirectional) edges that have u
    for i = 0 ... |V|
        if(G[i] is not empty) return false;
        return true;
}

我在很多图上尝试这个(但它们的最大尺寸是 20 个顶点),这需要十年的时间......我可以对这个蛮力做任何优化,让它运行得更快吗?

4

0 回答 0