G. Rabbit Party

Time Limit: 5000ms
Case Time Limit: 5000ms
Memory Limit: 65536KB
64-bit integer IO format: %lld      Java class name: Main
Font Size: 
+
 
-

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, uv and fu and v (1
¥leq u, v ¥leq n
u ¥neq v1 ¥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图论)的更多相关文章

  1. Aizu 2306 Rabbit Party DFS

    Rabbit Party Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view. ...

  2. Aizu 2309 Sleeping Time DFS

    Sleeping Time Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...

  3. [WorldFinal 2012E]Infiltration(dfs+图论)

    Description 题意:给定一个点数为n的竞赛图,求图的最小支配集 n<=75 Solution 如果将竞赛图的一个点删去,这个图还是竞赛图 而竞赛图每个点相连的边数为(n-1),那么删去 ...

  4. Aizu 2300 Calender Colors dfs

    原题链接:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2300 题意: 给你一个图,让你生成一个完全子图.使得这个子图中每个点的最 ...

  5. CF R639 div 2 E Quantifier Question 数学 dfs 图论

    LINK:Quantifier Question 题面过长 引起不适 读题花了好长时间 对于 和 存在符合不是很熟练 导致很懵逼的做完了. 好在还算很好想.不过wa到了一个坑点上面 自闭一大晌 还以为 ...

  6. BZOJ 1064: [Noi2008]假面舞会(dfs + 图论好题!)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1064 题意: 思路: 考虑以下几种情况: ①无环并且是树: 无环的话就是树结构了,树结构的话想一下就 ...

  7. codeforces 723E:One-Way Reform

    Description There are n cities and m two-way roads in Berland, each road connects two cities. It is ...

  8. Codeforces Round #479 (Div. 3)题解

    CF首次推出div3给我这种辣鸡做,当然得写份博客纪念下 A. Wrong Subtraction time limit per test 1 second memory limit per test ...

  9. PAT甲级专题|最短路

    PAT甲级最短路 主要算法:dijkstra 求最短最长路.dfs图论搜索. 1018,dijkstra记录路径 + dfs搜索路径最值 25分,错误点暂时找不出.. 如果只用dijkstra没法做, ...

随机推荐

  1. 剑指Offer面试题33(java版):把数组排成最小的数

    题目:输入一个正整数数组.把数组里面全部的数字拼接排成一个数,打印能拼接出的全部数字中的一个.比如输入数组{3,32.321}.则打印出这3个数字能排成的最小数字321323. 这个题目最直接的做法应 ...

  2. poj 1182 食物链 &amp;&amp; nyoj 207(种类并查集)

    食物链 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 52414   Accepted: 15346 Description ...

  3. vijos- P1385盗窃-月之眼 (水题 + python)

    P1385盗窃-月之眼 Accepted 标签:怪盗基德 VS OIBH[显示标签] 背景 怪盗基德 VS OIBH 第三话 描写叙述 怪盗基德第三次来到熟悉的OIBH总部.屡屡失败的OIBH这次看守 ...

  4. 求包含每个有序数组(共k个)至少一个元素的最小区间

    title: 求包含每个有序数组(共k个)至少一个元素的最小区间 toc: false date: 2018-09-22 21:03:22 categories: OJ tags: 归并 给定k个有序 ...

  5. HTML-虚线框3例

    第一例: 代码 <HR style=> 第二例: 代码 <DIV style="BORDER-TOP: #00686b 1px dashed; OVERFLOW: hidd ...

  6. 异步编程(二)基于事件的异步编程模式 (EAP)

    一.引言 在上一个专题中为大家介绍了.NET 1.0中提出来的异步编程模式——APM,虽然APM为我们实现异步编程提供了一定的支持,同时它也存在着一些明显的问题——不支持对异步操作的取消和没有提供对进 ...

  7. Rabbit MQ 学习 (一)Window安装Erlang环境

    之前也没有用过Rabbit MQ ,最近正在学习中,记性不好,特意记一下. 百度一下 先得 安装 Erlang 并且 设置环境变量. 在Erlang 官网去下载,那个慢呀... 还好CSDN 里有人提 ...

  8. 微信小程序调试 Webview

    document.querySelectorAll("webview")[1].showDevTools(true);

  9. Comparison of programming languages

    The following table compares general and technical information for a selection of commonly used prog ...

  10. Linux(1)---常用命令

    1.将tgz文件解压到指定目录: # tar zxvf test.tgz -C 指定目录 比如将 /lyl/test.tgz解压到 /lyl/linux 目录下 # tar zxvf /lyl/tes ...