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个包,每一个包里有若干个宝石,给出宝石的颜色. ...
随机推荐
- 实用的eclipse adt 快捷键
Ctrl + Shift + T: 打开类型:显示"打开类型"对话框来在编辑器中打开类型."打开类型"选择对话框显示工作空间中存在的所有类型如类.接口等. ...
- Angularjs中input的指令和属性
建议添加 novalidate属性(可无值)到form标签上,这样可以保证在表单不合法的情况下阻止浏览器继续提交数据. 可以给表单元素 input 添加 required 属性(可无值),让该表单成为 ...
- storm - 基础概念整理
理论 Hadoop的出现虽然为大数据计算提供了一条捷径,但其仍然存在自身难以克服的缺点:实时性不足.Hadoop的一轮计算的启动需要较长时间,因此其满足不了对实时性有较高要求的场景. Storm由此应 ...
- mvc源码解读(20)-controller和view之查找view
很多时候在mvc项目中我们需要去扩展自己的视图引擎,大概看起来应该下面这个样子的: public class RazorEngineExpand : RazorViewEngine { private ...
- apache开源项目--Camel
Apache Camel 是一个非常强大的基于规则的路由以及媒介引擎,该引擎提供了一个基于POJO的 企业应用模式(Enterprise Integration Patterns)的实现,你可以采用其 ...
- DOM事件逐层上机传递
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- How to Convert a Date Time to “X minutes ago” in C# z
http://www.codeproject.com/Articles/770323/How-to-Convert-a-Date-Time-to-X-minutes-ago-in-Csh In one ...
- sun X509/X500Name异常(已解决)
appium环境搭建好后,再跑第一个脚本时遇到这个问题: Errors occurred during the build.Errors running builder 'Android Packag ...
- 如何学习ios开发
著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处.作者:Franz Fang链接:http://www.zhihu.com/question/20264108/answer/3026 ...
- 【译】 AWK教程指南 7AWK应用实例
本节将示范一个统计上班到达时间及迟到次数的程序. 这程序每日被执行时将读入两个数据文件: * 员工当日到班时间的数据文件 ( 如下列的 arr.dat ) * 存放员工当月迟到累计次数的文件 当程序执 ...