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没法做, ...
随机推荐
- mycat 连续分片 -> 自己定义数字范围分片
1,自己定义数字范围分片 自己定义数字范围分片,提前规划好分片字段某个范围属于哪个分片,比方说将第一个500W的数据分片在第一个节点上面.第二个500W的数据分片在第二个节点上,依次类推 2,加入配置 ...
- UML期末绘图及细节总结
往届期末绘图的题目例如以下所看到的: Read the providing materials carefully, and then do tasks. 2.1: Use Case Diagram ...
- iframe是否缓存页面探究
近期手里有个项目须要用iframe来调用每天都会变化的页面,后来想到iframe会不会缓存页面呢.于是写了个demo论证了下,结果例如以下: iframe的src假设是静态页面,就有可能会缓存.由于静 ...
- 算法入门经典第七章 例题7-2-1 生成1-n的排列
输入正数n,按字典序从小到大的顺序输出n个数的所有排列.两个序列的字典序大小关系等价于从头开始第一个不相同位置处的大小关系. 递归的边界应该很好理解吧,当集合s[]中没有一个元素的时候,按照上面的伪码 ...
- element-ui自定义table表头,修改列标题样式
elementUI table表格一般的样式是这样的: 但是要改变表头是比较麻烦的一个事情,但是往往有些项目是需要的比如改成如下样式: 一般直接改起来挺麻烦,好在官网提供了一个方法:render-he ...
- Activity、Fragment、ViewPage
1.新建super //super提供统一的FragmentActivity入口.public abstract class SuperFragmentActivity extends Fragmen ...
- WPF动态控件生成查找不到问题
2012 08 10 遇到此类问题,已经找到解决方案 记录以备后用 动态往界面添加控件 在页面未显示的情况时,虽然对控件增加了id name等属性但是使用 TextBox txtOtherNati ...
- json字符串与json对象的相互转换
什么是 JSON ? JSON 指的是 JavaScript 对象表示法(JavaScript Object Notation) JSON 是轻量级的文本数据交换格式 JSON 独立于语言 * JSO ...
- BAT三家互联网公司哪家更注重用户体验?
这几天百度的用户体验又成了设计圈关注的对象,李彦宏好不容易刷出来的好感度一下子被打入了冰点,通过此次事件,不难看出现在的互联网用户对于产品的体验要求越来越高,作为一名美图秀秀级别选手,很难领悟“好设计 ...
- Unity5.X 创建基本的3D游戏场景
点New(新建懒得写了,反正不是智障应该都会) 创建好的项目会自带一个场景,场景会自带Main Camera (主摄像机),Directional Light (方向光) 系统自带几个可以创建的3 ...