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个包,每一个包里有若干个宝石,给出宝石的颜色. ...
随机推荐
- IT项目量化管理:细化、量化与图形化 与 中国IT项目实施困惑
IT项目开发和实施的组织先后在组织中引入项目管理模型的管理制度.流程和方法,但收入甚微.大量的IT项目依然面临着无休止的需求蔓延与频繁加班.项目工期失控.质量低下等典型的项目失控现象.对项目引入量化意 ...
- poj2478
比较简单的树形dp; 定义s[i]为节点i的子树节点数和(包括自身):叶子节点s[j]=1; s[i]=signma(s[k])+1 (k是i的孩子) 则i满足的条件是 1.s[k]<=n di ...
- C#中父窗口和子窗口之间实现控件互操作
很多人都苦恼于如何在子窗体中操作主窗体上的控件,或者在主窗体中操作子窗体上的控件.相比较而言,后面稍微简单一些,只要在主窗体中创建子窗体的时候,保留所创建子窗体对象即可. 下面重点介绍前一种,目前常见 ...
- UVa 12171 (离散化 floodfill) Sculpture
题意: 三维空间中有n个长方体组成的雕塑,求表面积和体积. 分析: 我们可以在最外边加一圈“空气”,然后求空气的连通块的体积,最后用总体积减去即是雕塑的体积. 还有一个很“严重”的问题就是5003所占 ...
- 学习面试题(day01)
1.什么是JVM及其工作原理? JVM是一种用软件模拟出来的计算机,它用于执行Java程序,有一套非常严格的技术规范,是Java跨平台特性的依赖基础.Java虚拟机有自己想象中的硬件,如处理器.堆栈. ...
- 解决android手机sd卡安装pak后直接打开,按home键异常问题
if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) { finish(); return; }
- HDU 5607 graph 矩阵快速幂 + 快速幂
这道题得到了学长的助攻,其实就是一个马尔科夫链,算出一步转移矩阵进行矩阵快速幂就行了,无奈手残 这是我第一回写矩阵快速幂,写的各种毛病,等到调完了已经8点44了,交了一发,返回PE,(发现是少了换行) ...
- [King.yue]Ext中Grid得到选择行数据的方法总结
(1)grid.getStore().getRange(0,store.getCount()); //得到grid所有的行 (2)grid.getSelectionModel().getSele ...
- opencv开发的程序分发给客户时所需要的dll文件
这里主要讲在其他裸机,没有搭建开发环境机器上运行自己开发的程序. 为了测试,我专门用visualbox搭建了一个虚拟机(主机和虚拟机都是win7系统) 在发给别人程序运行出现错误:msvcp100d. ...
- Windows mysql 5.6 zip 安装 并创建用户赋予数据库权限
1.下载mysql 5.6 zip 首先下载mysql 5.6 zip (在官网(http://www.mysql.com/downloads/) 或者其他网站都行), 然后解压在自己的电脑上 D:\ ...