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;
    }
  • 相关阅读:
    fastlane
    OSI 模型
    iOS面试—0、技术点
    Git 提交规范
    iOS Aggregate 合并静态库
    iOS 应用分发平台
    json 转swift的工具
    敏捷开发
    mac 打包dmg
    iOS 获取素材
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4851579.html
Copyright © 2011-2022 走看看