zoukankan      html  css  js  c++  java
  • 2019牛客暑期多校训练营(第二场)D Kth Minimum Clique(第k团)

    题意:给你n个点 求第k小的团

    思路:暴力bfs+bitset压位

    #include <bits/stdc++.h>
    using namespace std;
    const int N = 1e5+7;
    const int inf = 0x3f3f3f3f;
    typedef long long ll;
    typedef bitset<107> bs;
    struct node{
        ll v;
        bs t;
        friend bool operator < (node a,node b){
            return a.v>b.v;
        }
    };
    int n,k;
    ll w[107];
    bs G[107];
    void bfs(){
        priority_queue<node> q;
        bs t; t.reset();
        q.push((node){0,t});
        while(!q.empty()){
            node tmp=q.top();
            q.pop();
            k--;
            if(k==0){
                cout<<tmp.v<<endl;
                return ;
            }
            bs r=tmp.t;
            int po=0; for(int i=0;i<n;i++) if(r[i]) po=i+1;
            for(int i=po;i<n;i++){
                if(!r[i]&&((r&G[i])==r)){
                    r[i]=1;
                    node a=(node){tmp.v+w[i],r};
                    q.push(a);
                    r[i]=0;
                }
            }
        }
        cout<<"-1"<<endl;
        return ;
    }
    int main(){
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
        cin>>n>>k;
        for(int i=0;i<n;i++){
            cin>>w[i];
        }
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++){
                char a; cin>>a;
                if(a=='1'){
                    G[i][j]=1;
                }
            }
        bfs();
        return 0;
    }
  • 相关阅读:
    Hdu 1257 最少拦截系统
    Hdu 1404 Digital Deletions
    Hdu 1079 Calendar Game
    Hdu 1158 Employment Planning(DP)
    Hdu 1116 Play on Words
    Hdu 1258 Sum It Up
    Hdu 1175 连连看(DFS)
    Hdu 3635 Dragon Balls (并查集)
    Hdu 1829 A Bug's Life
    Hdu 1181 变形课
  • 原文地址:https://www.cnblogs.com/wmj6/p/11258416.html
Copyright © 2011-2022 走看看