Aizu - 2306 Rabbit Party (DFS图论)
G. Rabbit Party
pid=39423" class="goprob button ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="margin:0px 0.1em 0px -1px; padding:0px; text-decoration:none; font-family:'Trebuchet MS',Helvetica,Arial,sans-serif; font-size:1.1em; border:1px solid rgb(204,204,204); font-weight:bold; color:rgb(68,68,68); display:inline-block; position:relative; zoom:1; overflow:visible">PID:
39423
+
-
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
¥leq n ¥leq 100, 0 ¥leq m ¥leq 100). The rabbits are numbered from 1to 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 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
分析题目,因为给你的全然图(即一个顶点与其它的顶点都有边)
接着从题目能够分析的n * (n - 1) / 2 = m <= 100
(提示。假设一个点与其它点之间的友好值为0,那么能够去掉这个点,或者那个与它的边为0的点。大家能够思考一下,所以为零的能够直接去掉)
得知n <= 15所以,实际上仅仅有15个数,那么我们能够DFS,得到这些数都是不会超时的
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <iostream>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <algorithm>
using namespace std; #define pb push_back
#define mp make_pair
#define fillchar(a, x) memset(a, x, sizeof(a))
#define copy(a, b) memcpy(a, b, sizeof(a))
#define S_queue<P> priority_queue<P, vector<P>,greater<P> > typedef long long LL;
typedef pair<int, int > PII;
typedef unsigned long long uLL;
template<typename T>
void print(T* p, T* q, string Gap = " "){int d = p < q ? 1 : -1;while(p != q){cout << *p;p += d;if(p != q) cout << Gap; }cout << endl;}
template<typename T>
void print(const T &a, string bes = "") {int len = bes.length();if(len >= 2)cout << bes[0] << a << bes[1] << endl;else cout << a << endl;} const int INF = 0x3f3f3f3f;
const int MAXM = 1e2 + 5;
const int MAXN = 1e2 + 5;
int Fig[MAXN][MAXN], Max;
int X[25], n, m; void Deal(int s){
int f , ans = 0;
for(int i = 1;i <= s;i ++){
f = INF;
for(int j = 1;j <= s;j ++){
if(i == j) continue;
f = min(f, Fig[X[i]][X[j]]);
}
if(f != INF)
ans += f;
}
Max = max(ans, Max);
}
void DFS(int u){
Deal(u);
int st = X[u] + 1;
if(u == 0) st = 1;
for(int i = st;i <= n;i ++){
bool flag = true;
for(int j = 1;j < u;j ++){
if(Fig[i][X[j]] == 0) {
flag = false;
break;
}
}
X[u + 1] = i;
if(flag) DFS(u + 1);
}
} int main(){
int u, v, d;
while(cin >> n >> m){
Max = 0;
memset(Fig, 0, sizeof(Fig));
for(int i = 1;i <= m;i ++){
cin >> u >> v >> d;
Fig[u][v] = Fig[v][u] = d;
Max = max(Max, d * 2);
}
DFS(0);
print(Max);
}
return 0;
}
Aizu - 2306 Rabbit Party (DFS图论)的更多相关文章
- Aizu 2306 Rabbit Party DFS
Rabbit Party Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view. ...
- Aizu 2309 Sleeping Time DFS
Sleeping Time Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...
- [WorldFinal 2012E]Infiltration(dfs+图论)
Description 题意:给定一个点数为n的竞赛图,求图的最小支配集 n<=75 Solution 如果将竞赛图的一个点删去,这个图还是竞赛图 而竞赛图每个点相连的边数为(n-1),那么删去 ...
- Aizu 2300 Calender Colors dfs
原题链接:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2300 题意: 给你一个图,让你生成一个完全子图.使得这个子图中每个点的最 ...
- CF R639 div 2 E Quantifier Question 数学 dfs 图论
LINK:Quantifier Question 题面过长 引起不适 读题花了好长时间 对于 和 存在符合不是很熟练 导致很懵逼的做完了. 好在还算很好想.不过wa到了一个坑点上面 自闭一大晌 还以为 ...
- BZOJ 1064: [Noi2008]假面舞会(dfs + 图论好题!)
http://www.lydsy.com/JudgeOnline/problem.php?id=1064 题意: 思路: 考虑以下几种情况: ①无环并且是树: 无环的话就是树结构了,树结构的话想一下就 ...
- codeforces 723E:One-Way Reform
Description There are n cities and m two-way roads in Berland, each road connects two cities. It is ...
- Codeforces Round #479 (Div. 3)题解
CF首次推出div3给我这种辣鸡做,当然得写份博客纪念下 A. Wrong Subtraction time limit per test 1 second memory limit per test ...
- PAT甲级专题|最短路
PAT甲级最短路 主要算法:dijkstra 求最短最长路.dfs图论搜索. 1018,dijkstra记录路径 + dfs搜索路径最值 25分,错误点暂时找不出.. 如果只用dijkstra没法做, ...
随机推荐
- java书籍推荐:《Java SE 6 技術手册》
Java SE 6 技術手册 或 Java SE 6 技術手册 Java SE 6 技術手册 為什麼選擇用 Markdown?仅仅是單純把文件又一次排版太無聊了,不如趁這個機會學些新東西.所以我就藉 ...
- UVa 170 - Clock Patience
题目:Clock Patience游戏,将52张扑克牌,按时钟依次分成13组(中心一组),每组4张全都背面向上, 从中间组最上面一张牌開始.翻过来设为当前值,然后取当前值相应组中最上面的背过去的牌翻过 ...
- USACO holstein 超时代码
/* ID:kevin_s1 PROG:holstein LANG:C++ */第八组数据跪了.半天都不出结果 #include <iostream> #include <cstdi ...
- UFLDL教程笔记及练习答案五(自编码线性解码器与处理大型图像**卷积与池化)
自己主动编码线性解码器 自己主动编码线性解码器主要是考虑到稀疏自己主动编码器最后一层输出假设用sigmoid函数.因为稀疏自己主动编码器学习是的输出等于输入.simoid函数的值域在[0,1]之间,这 ...
- STL_算法_依据第n个元素排序(nth_element)
C++ Primer 学习中... 简单记录下我的学习过程 (代码为主) //全部容器适用 nth_element(b,n,e) nth_element(b,n,e,p) 对照:partition() ...
- Oracle数据的基本操作
一.什么是Oracle 在学习DRP系统之前,非常多次提到过Oracle,也了解过,那么Oracle是什么?今天我最终揭开了它的神奇面纱. Oracle:是一个公司.当然我在这里说的是Oracle数据 ...
- hive1.2伪分布mysql数据库配置具体解释
hadoop2.6伪分布配置:http://blog.csdn.net/gamer_gyt/article/details/46793731 hive1.2 derby元数据库配置:http://b ...
- 杂项-电信:TL9000
ylbtech-杂项-电信:TL9000 TL9000是电信业质量体系要求(书1)与质量体系法则(书2)的指南, 它包括ISO9001的所有要求,以及硬件.软件, 服务方面行业的特别要求. 这些新增要 ...
- jqueryui slider
<!doctype html><html lang="en"><head> <meta charset="utf-8" ...
- [jzoj 5661] 药香沁鼻 解题报告 (DP+dfs序)
interlinkage: https://jzoj.net/senior/#contest/show/2703/0 description: solution: 注意到这本质就是一个背包,只是选了一 ...