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个包,每一个包里有若干个宝石,给出宝石的颜色. ...
随机推荐
- Where is Vasya?
Where is Vasya? Vasya stands in line with number of people p (including Vasya), but he doesn't know ...
- Angularjs中input的指令和属性
建议添加 novalidate属性(可无值)到form标签上,这样可以保证在表单不合法的情况下阻止浏览器继续提交数据. 可以给表单元素 input 添加 required 属性(可无值),让该表单成为 ...
- apache开源项目--ZooKeeper
ZooKeeper是Hadoop的正式子项目,它是一个针对大型分布式系统的可靠协调系统,提供的功能包括:配置维护.名字服务.分布式同步.组服务等.ZooKeeper的目标就是封装好复杂易出错的关键服务 ...
- onAttachedToWindow () 和 onDetachedFromWindow () ; 以及更新视图的函数ondraw() 和dispatchdraw()的区别
protected void onAttachedToWindow() This is called when the view is attached to a window. At this po ...
- NetCat简介与使用方法
精品学习网考试频道小编应广大考生的需要,特为参加考试的考生策划了“NetCat简介与使用方法”专题等有关资料,供考生参考! 在入侵中它是最经典的工具之一 ,NetCat被所有的网络安全爱好者和研究者称 ...
- Windbg源码调试
Windbg提供比VS2008丰富很多的调试命令,尤其是调试多线程程序. 今天试着怎么使用源代码方式调试.为了说明调试命令,<C++标准库>一书里的例子做示范. // testcast.c ...
- python引用在函数传参时的体现以及可变与不可变对象的对比
今天偶然看到 vamei 老师的博客 http://www.cnblogs.com/vamei/archive/2012/07/10/2582795.html 讲的是python动态类型以及引用的事儿 ...
- <转>DNS SOA记录
http://www.sigma.me/2011/01/01/about_dns_soa.html 今天登入google webmaster,发现有好多crawl错误,一看,都是Domain name ...
- as3 工具类分享 CookieMgr
今天分享一个工具类 CookieMgr,功能就是读取和写入 SharedObject 对象.很简单,都是静态方法,就不多说了 package org.polarbear.core { import f ...
- Channel 详解
java.nio.channels.FileChannel封装了一个文件通道和一个FileChannel对象,这个FileChannel对象提供了读写文件的连接. 1.接口 2.通道操作 a.所有通道 ...