Aizu 2306 Rabbit Party DFS
Rabbit Party
Time Limit: 1 Sec
Memory Limit: 256 MB
题目连接
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=93265#problem/G
Description
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 1 to 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
3 3
1 2 3
2 3 1
3 1 2
Sample Output
6
HINT
题意
给你一个完全图,然后给你m个边的边权,其他边的权值都是0
然后让你选择一个点集出来,点权是这个点连接这个点集的边权最小值
然后要求你选的点集的点权和最大
题解:
直接暴力就好了,我们最后选出来的点,一定是由那m个边所组成的完全图
那么只有100个边,所以最多就是15个点的完全图
就直接暴力出来所有完全图,然后取一个最大值就好了
@)1%KBO0HM418$J94$1R.jpg)
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn = 1e2 + ;
int mat[maxn][maxn],n,m;
vector<int> Q; int ans = ;
int vis[maxn]; void dfs(int x)
{ int temp = ;
for(int i=;i<Q.size();i++)
{
int minn = ;
for(int j=;j<Q.size();j++)
{
if(i==j)continue;
minn = min(mat[Q[i]][Q[j]],minn);
}
if(minn==)
minn=;
temp += minn;
}
ans = max(ans,temp); for(int i=x+;i<=n;i++)
{
if(vis[i])continue;
int flag = ;
for(int j=;j<Q.size();j++)
{
if(!mat[i][Q[j]])
{
flag = ;
break;
}
}
if(flag)
{
vis[i]=;
Q.push_back(i);
dfs(i);
vis[i]=;
Q.pop_back();
}
} } int main(int argc, char *argv[])
{
scanf("%d%d",&n,&m);
for(int i = ; i < m ; ++ i)
{
int u , v , w;
scanf("%d%d%d",&u,&v,&w);
mat[u][v] = mat[v][u] = w;
} for(int i=;i<=n;i++)
{
Q.push_back(i);
vis[i]=;
dfs();
Q.pop_back();
vis[i]=;
}
printf("%d\n",ans);
return ;
}
Aizu 2306 Rabbit Party DFS的更多相关文章
- Aizu - 2306 Rabbit Party (DFS图论)
G. Rabbit Party Time Limit: 5000ms Case Time Limit: 5000ms Memory Limit: 65536KB 64-bit integer IO f ...
- Aizu 2309 Sleeping Time DFS
Sleeping Time Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...
- Aizu 2300 Calender Colors dfs
原题链接:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2300 题意: 给你一个图,让你生成一个完全子图.使得这个子图中每个点的最 ...
- Aizu 2302 On or Off dfs/贪心
On or Off Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.act ...
- Aizu 0033 Ball(dfs,贪心)
日文题面...题意:是把一连串的有编号的球往左或者往右边放.问能不能两边都升序. 记录左边和右边最上面的球编号大小,没有就-1,dfs往能放的上面放. #include<bits/stdc++. ...
- Aizu - 2305 Beautiful Currency (二分 + DFS遍历)
F. Beautiful Currency Time Limit: 5000ms Case Time Limit: 5000ms Memory Limit: 65536KB 64-bit intege ...
- 【Aizu - 0525】Osenbei (dfs)
-->Osenbei 直接写中文了 Descriptions: 给出n行m列的0.1矩阵,每次操作可以将任意一行或一列反转,即这一行或一列中0变为1,1变为0.问通过任意多次这样的变换,最多可以 ...
- Aizu 0531 "Paint Color" (坐标离散化+DFS or BFS)
传送门 题目描述: 为了宣传信息竞赛,要在长方形的三合板上喷油漆来制作招牌. 三合板上不需要涂色的部分预先贴好了护板. 被护板隔开的区域要涂上不同的颜色,比如上图就应该涂上5种颜色. 请编写一个程序计 ...
- hdu 4778 Rabbit Kingdom(减少国家)
题目链接:hdu 4778 Rabbit Kingdom 题目大意:Alice和Bob玩游戏,有一个炉子.能够将S个同样颜色的宝石换成一个魔法石.如今有B个包,每一个包里有若干个宝石,给出宝石的颜色. ...
随机推荐
- 基于邻接表的广度优先搜索遍历(bfs)
题目:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2142&cid=1186 #include<stdio.h> #incl ...
- 宏HASH_INSERT
调用 方法 HASH_INSERT(lock_t, hash, lock_sys->rec_hash,lock_rec_fold(space, page_no), lock); /******* ...
- 手机3D游戏开发:自定义Joystick的相关设置和脚本源码
Joystick在手游开发中非常常见,也就是在手机屏幕上的虚拟操纵杆,但是Unity3D自带的Joystick贴图比较原始,所以经常有使用自定义贴图的需求. 下面就来演示一下如何实现自定义JoySti ...
- js匿名函数
<script type="text/javascript"> $(function () { $("#btn").mousedown(functi ...
- FJOI2007轮状病毒
不会推公式…… 不会基尔霍夫矩阵…… 不会matrix—tree定理…… 膜拜vfleaking大神…… 题解:http://z55250825.blog.163.com/blog/static/15 ...
- JavaEE基本了解
1. 为什么需要JavaEE 我们编写的JSP代码中,由于大量的显示代码和业务逻辑混淆在一起,彼此嵌套,不利于程序的维护和扩展.当业务需求发生变化的时候,对于程序员和美工都是一个很重的负担. 为了程 ...
- Javascript 知识点简介
如何在HTML中引入JS? 所有重定向的HTML标签内都可以嵌入javascript代码. 浮点数不要用 == 来进行判断 var num=0; for(var i=0;i<10;i++) ...
- MemoryMappedFile 内存映射文件 msdn
http://msdn.microsoft.com/zh-cn/library/dd997372%28v=vs.110%29.aspx 内存映射文件 .NET Framework 4.5 其他版本 1 ...
- 在windows10+word2010中完美使用北大方正word公式输入法总结
如果在安装输入法时遇到了无法安装的情况,请首先百度下VC运行库安装下(32位64位都安就是),然后安装北大方正word公式输入法,此时不会再提示无法安装,接着(关键)在word应用程序图标右键-> ...
- UVA 11183 Teen Girl Squad 最小树形图
最小树形图模板题 #include <iostream> #include <algorithm> #include <cstdio> #include <c ...