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. System v shm的key

    shmget函数用于创建或打开一个共享内存区对象,shmget成功调用会返回一个共享内存区的标识符,供其它的共享内存区操作函数使用. key:用于创建共享内存区的键值,这个在前面其他System IP ...

  2. HDU 4354

    思路是在看电视时突然想到的.枚举区间,然后按树形DP来选择最大值看是否满足条件.但枚举区间时的方法低效,看了题解,说枚举区间可以设两个指针逐步移动, 开始 l = r = 1, 记录已经出现的国家. ...

  3. 上机题目(0基础)- Java网络操作-Socket实现client和server端通信(Java)

    非常多刚開始学习的人对于java网络通信不太熟悉.对相关概念也不太明确,这里我们主要实现一下socket通信,socket通信在java中应用十分广泛.比如QQ和MSN等都是基于socket通信的,什 ...

  4. 路由器wiff设置

    1.将一根网线连接至路由wankou 2.将另外一根网页连接1.2.3.4口中一个,另外一个连接至电脑 3.登录192.168.1.1,进行设置向导选择ppoe,然后登录网络设置无线名称+密码 4.保 ...

  5. 广东工业大学2016校赛决赛-网络赛 1169 Problem A: Krito的讨伐 优先队列

    Problem A: Krito的讨伐 Description Krito终于干掉了99层的boss,来到了第100层.第100层可以表示成一颗树,这棵树有n个节点(编号从0到n-1),树上每一个节点 ...

  6. 这里是指推送通知跟NSNotification有区别:

    1.NSNotification是系统内部发出通知,一般用于内部事件的监听,或者状态的改变等等,是不可见的2.本地通知与远程通知是可见的,主要用于告知用户或者发送一些App的内容更新,推送一些相关的消 ...

  7. Asp.net Web Api中使用配置Unity

    第一步:建立web api,添加unity.webapi. 第二步:在添加了该引用之后,在App_Start中会自动生成UnityConfig.cs文件 第三步:添加数据做测试 第四步:展示效果

  8. css实战笔记(一):写网页前的reset工作

    reset.css是每个html必备的样式,其中有各种元素属性清零的代码. 为什么要有reset.css 让各个浏览器的CSS样式有一个统一的基准,比如清除各个浏览器为元素自带的margin.padd ...

  9. GradientDrawable类的利用动态设置样式中的颜色

    1.xml样式文件 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android=& ...

  10. [C#学习笔记之异步编程模式2]BeginInvoke和EndInvoke方法 (转载)

    为什么要进行异步回调?众所周知,普通方法运行,是单线程的,如果中途有大型操作(如:读取大文件,大批量操作数据库,网络传输等),都会导致方法阻塞,表现在界面上就是,程序卡或者死掉,界面元素不动了,不响应 ...