题目链接:点击打开链接
题意:
给定n个点的完全图,下面给出m条边权不为0的边
下面m行给出边和边权。
其他的边边权都为0.
选择一个顶点导出子图,该子图的每个点点权为 该点连接的最小边权。
找一个这样的子图使得点权和最大,输出点权和。
思路:
因为是一个完全图,所以我们选择的点构成的图一定不包含权值为0的边。因为若包含了权值为0的边,则大可以把这两点删掉而不会减小答案。
所以我们选择的图中的边一定只 包含给出的m条边,且由这m条边构成的一个团。
再判断一下这个团中最多的点数,设最多有n个点,则这个团的边数为 n*(n-1)/2 ,而输入最多只有100条边
即 n*(n-1)/2 <= 100 => n <=14
所以爆搜这14个点就可以了
#include<bits/stdc++.h> template <class T> inline bool rd(T &ret) { char c; int sgn; if(c=getchar(),c==EOF) return 0; while(c!='-'&&(c<'0'||c>'9')) c=getchar(); sgn=(c=='-')?-1:1; ret=(c=='-')?0:(c-'0'); while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0'); ret*=sgn; return 1; } template <class T> inline void pt(T x) { if (x <0) { putchar('-'); x = -x; } if(x>9) pt(x/10); putchar(x%10+'0'); } using namespace std; typedef long long ll; const int N = 105; int ans, mp[N][N]; int a[20], d[20], n; void work(int n){ int c = 0, cc; for(int i = 1; i <= n; i++) { cc = 1e8; for(int j = 1; j <= n; j++) if(i!=j) cc = min(cc, mp[a[i]][a[j]]); c += cc; } ans = max(ans, c); } void dfs(int u){ if(u >= 3)work(u-1); for(int i = a[u-1]+1; i <= n; i++) { bool ok = true; for(int j = 1; j < u && ok; j++) if(mp[i][a[j]] == 0) ok = false; a[u] = i; if(ok)dfs(u+1); } } int main(){ int u, v, d, m; while(cin>>n>>m){ ans = 0; memset(mp, 0, sizeof mp); while(m--){ rd(u);rd(v);rd(d); mp[u][v] = mp[v][u] = d; ans = max(ans, d<<1); } dfs(1); cout<<ans<<endl; } return 0; }
Rabbit Party
Time Limit : 5 sec, Memory Limit : 65536 KB
Rabbit Party
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≤n≤100, 0≤m≤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≤u,v≤n, u≠v, 1≤f≤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 1
3 3 1 2 3 2 3 1 3 1 2
Output for the Sample Input 1
6
Sample Input 2
2 1 1 2 5
Output for the Sample Input 2
10
Sample Input 3
1 0
Output for the Sample Input 3
0
Sample Input 4
4 5 1 2 4 1 3 3 2 3 7 2 4 5 3 4 6
Output for the Sample Input 4
16