zoukankan      html  css  js  c++  java
  • Aizu 2306 Rabbit Party DFS

    Rabbit Party

    Time Limit: 1 Sec  

    Memory Limit: 256 MB

    题目连接

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=93265#problem/G

    Description

    A rabbit Taro decided to hold a party and invite some friends as guests. He has n rabbit friends, and m pairs of rabbits are also friends with each other. Friendliness of each pair is expressed with a positive integer. If two rabbits are not friends, their friendliness is assumed to be 0.

    When a rabbit is invited to the party, his satisfaction score is defined as the minimal friendliness with any other guests. The satisfaction of the party itself is defined as the sum of satisfaction score for all the guests.

    To maximize satisfaction scores for the party, who should Taro invite? Write a program to calculate the maximal possible satisfaction score for the party.

    Input

    The first line of the input contains two integers, n and m (1 leq n leq 1000 leq m leq 100). The rabbits are numbered from 1 to n.

    Each of the following m lines has three integers, uv and fu and v (1 leq u, v leq nu eq v1 leq f leq 1,000,000) stands for the rabbits' number, and f stands for their friendliness.

    You may assume that the friendliness of a pair of rabbits will be given at most once.

    Output

    Output the maximal possible satisfaction score of the party in a line.

    Sample Input

    3 3
    1 2 3
    2 3 1
    3 1 2

    Sample Output

    6

    HINT

    题意

    给你一个完全图,然后给你m个边的边权,其他边的权值都是0

    然后让你选择一个点集出来,点权是这个点连接这个点集的边权最小值

    然后要求你选的点集的点权和最大

    题解:

    直接暴力就好了,我们最后选出来的点,一定是由那m个边所组成的完全图

    那么只有100个边,所以最多就是15个点的完全图

    就直接暴力出来所有完全图,然后取一个最大值就好了

    代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <vector>
    using namespace std;
    const int maxn = 1e2 + 15;
    int mat[maxn][maxn],n,m;
    vector<int> Q;
    
    int ans = 0;
    int vis[maxn];
    
    void dfs(int x)
    {
    
        int temp = 0;
        for(int i=0;i<Q.size();i++)
        {
            int minn = 8898989;
            for(int j=0;j<Q.size();j++)
            {
                if(i==j)continue;
                minn = min(mat[Q[i]][Q[j]],minn);
            }
            if(minn==8898989)
                minn=0;
            temp += minn;
        }
        ans = max(ans,temp);
    
    
        for(int i=x+1;i<=n;i++)
        {
            if(vis[i])continue;
            int flag = 1;
            for(int j=0;j<Q.size();j++)
            {
                if(!mat[i][Q[j]])
                {
                    flag = 0;
                    break;
                }
            }
            if(flag)
            {
                vis[i]=1;
                Q.push_back(i);
                dfs(i);
                vis[i]=0;
                Q.pop_back();
            }
        }
    
    
    }
    
    int main(int argc, char *argv[])
    {
        scanf("%d%d",&n,&m);
        for(int i = 0 ; i < m ; ++ i)
        {
            int u , v  , w;
            scanf("%d%d%d",&u,&v,&w);
            mat[u][v] = mat[v][u] = w;
        }
    
        for(int i=1;i<=n;i++)
        {
            Q.push_back(i);
            vis[i]=1;
            dfs(0);
            Q.pop_back();
            vis[i]=0;
        }
        printf("%d
    ",ans);
        return 0;
    }
  • 相关阅读:
    CopyOnWriteArrayList 读写分离,弱一致性
    Java中定时器Timer致命缺点(附学习方法)
    排队打饭:公平锁和非公平锁(面试)
    母鸡下蛋实例:多线程通信生产者和消费者wait/notify和condition/await/signal条件队列
    volatile,synchronized可见性,有序性,原子性代码证明(基础硬核)
    Synchronized用法原理和锁优化升级过程(面试)
    Java中多线程安全问题实例分析
    iOS 相互引用引起内存泄露问题说明
    iOS app 集成友盟推送问题
    ios即时通讯客户端开发之-mac上基于XMPP的聊天客户端开发环境搭建
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4851579.html
Copyright © 2011-2022 走看看