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 100, 0 \leq m \leq 100). The rabbits are numbered from 1 to n.
Each of the following m lines has three integers, u, v and f. u and v (1 \leq u, v \leq n, u \neq v, 1 \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 + ;
int mat[maxn][maxn],n,m;
vector<int> Q; int ans = ;
int vis[maxn]; void dfs(int x)
{ int temp = ;
for(int i=;i<Q.size();i++)
{
int minn = ;
for(int j=;j<Q.size();j++)
{
if(i==j)continue;
minn = min(mat[Q[i]][Q[j]],minn);
}
if(minn==)
minn=;
temp += minn;
}
ans = max(ans,temp); for(int i=x+;i<=n;i++)
{
if(vis[i])continue;
int flag = ;
for(int j=;j<Q.size();j++)
{
if(!mat[i][Q[j]])
{
flag = ;
break;
}
}
if(flag)
{
vis[i]=;
Q.push_back(i);
dfs(i);
vis[i]=;
Q.pop_back();
}
} } int main(int argc, char *argv[])
{
scanf("%d%d",&n,&m);
for(int i = ; i < m ; ++ i)
{
int u , v , w;
scanf("%d%d%d",&u,&v,&w);
mat[u][v] = mat[v][u] = w;
} for(int i=;i<=n;i++)
{
Q.push_back(i);
vis[i]=;
dfs();
Q.pop_back();
vis[i]=;
}
printf("%d\n",ans);
return ;
}