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没法做, ...
随机推荐
- 图像滤镜艺术---保留细节的磨皮之C#程序实现
上一篇博文"保留细节的磨皮滤镜之PS实现"一文中.我简介了本人自己总结的一种非常easy的磨皮滤镜,这个滤镜在磨光皮肤的同一时候,会保留非常不错的细节,今天,我将介绍使用C#程序实 ...
- 使用Service Bus Topic 实现简单的聊天室
创建Service Bus能够參照: https://azure.microsoft.com/en-gb/documentation/articles/service-bus-dotnet-how-t ...
- 怎样避免使用Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK之后的黑屏问题
在自己的项目中.我须要使用Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK来開始新的activity同一时候移除之前全部的 ...
- [yueqian_scut]Android多点触控技术和应用框架
Android多点触控技术跟Linux输入子系统紧密相关.本文将从应用的角度说明Android多点触控技术的接口和应用. 一.多点触控场景分析 网络上有关Android多点触控技术的文章多见于两点拉伸 ...
- 2017-3-6 leetcode 118 169 189
今天什么都没发生 ================================================= leetcode118 https://leetcode.com/problems ...
- java.lang.ClassNotFoundException: org.objectweb.asm.ClassWriter
转自:https://www.cnblogs.com/yfceshi/p/6814802.html Caused by: javax.xml.ws.WebServiceException: java. ...
- php如何判断两个时间戳是一天
$date1 = getdate(strtotime('2013-12-31')); $date11 = getdate(strtotime('2014-01-01')); $date2 = getd ...
- [实例]ROS使用OpenCV读取图像并发布图像消息在rviz中显示
思路: (1)使用opencv读取本地图像 (2)调用cv_bridge::CvImage().toImageMsg()将本地图像发送给rviz显示 一.使用opencv读取本地图像并发布图像消息 ( ...
- [转]SQL Server 数据库规范
SQL Server 数据库规范 一. 命名规范常用对象命名规范,使用帕斯卡命名法(Pascal,单词首字母大写),统一使用英文. 1. 表.英文单数名词,尽量写完整单词名称一般不超过3个英文单词都可 ...
- Windows 10 游戏录制工具栏