Cattle off-network multi-school training second field D Kth Minimum Clique

Links: https://ac.nowcoder.com/acm/contest/882/D
Source: Cattle-off network

 

Given a vertex-weighted graph with N vertices, find out the K-th minimum weighted clique.

A subset of vertices of an undirected graph is called clique if and only if every two distinct vertices in the subset are adjacent. The weight of a clique is the summation of the weight of vertices in it.

 

Meaning of the questions: Given a matrix to collarless access map, each point has the right values, the right to find out the value of a small group of k weights (a group that is a complete subgraph)

Problem-solving ideas: Obviously, we can know that the smallest group is empty complete graph, that is, 0-order complete subgraph, thus inspired, we can generate from this second small smallest group, the third small ... the group, because the second small, small ... the third group is the group to join an empty spot generated, the idea here is obviously one kind of breadth-first search

But how do we make out of each team are in accordance with the n small group, in this order of n + 1 small to do? Obviously, because right to the point value of each, but the size of the group is defined as the number of weight and size of points, not points, so this place, we use the priority queue implementation,

A small group of priority queues, which will guarantee the order of groups is dequeued group in descending order, ascending, because each group to form the new group will be greater, so the top of the stack n-th dequeue the group must be the first n small group, BFS simulate this process we can get the first k small groups.

PS: The title bitset represented by all the points of each group and the connection point, to optimize

#include <bits / STDC ++ H.> 
the using namespace STD; 
typedef Long Long LL; 
int n-, K; 
LL Val [105]; 
the bitset <105> STA [105]; // compressed state, i represents all points connected 
struct Node 
{ 
    LL W; 
    int ID; point // record the current group is added last point number, the current group added only added last point after, the purpose of de-emphasis of 
    the bitset <105> Clique; 
    Friend BOOL operator <(const Node & a, const Node & B) 
    { 
        return AW> BW; 
    } 
}; 
The priority_queue <Node> Q; 
int main () { 
    CIN >> n->> K; 
    for (int I =. 1; I <= n-; I ++) { 
        CIN >> Val [I]; 
    } 
    int X; 
    for (int I =. 1; I <= n-; I ++) 
            Scanf ( "%1d",&x);
            sta[i][j]=x;
        }
    ll ans=-1;
    node st;
    st.id=0;
    st.w=0;
    q.push(st);
    while (!q.empty())
    {
        node now = q.top();
        q.pop();
        k--;
        if(!k)
        {
            ans=now.w;
            break;
        }
        for(int i=now.id+1;i<=n;i++)
        {
            if((now.clique&sta[i])==now.clique)//说明点i与当前团中的点都相连
            {
                node next;
                next.id=i;
                next.clique=now.clique;
                next.clique[i]=1;
                next.w=now.w+val[i];
                q.push(next);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

 

Summary: The essence of the question is to find the largest group of DFS process parsed by the group to maintain a priority queue to get in, get the first k small groups.

Guess you like

Origin www.cnblogs.com/xusirui/p/11221952.html