UVa 140 Bandwidth:枚举全排列&剪枝搜索

140 - Bandwidth

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=108&page=show_problem&problem=76

Given a graph (V,E) where V is a set of nodes and E is a set of arcs in VxV, and anordering on the elements in V, then thebandwidth of a nodev is defined as the maximum distance in the ordering betweenv and any node to which it is connected in the graph. The bandwidth of the ordering is then defined as the maximum of the individual bandwidths. For example, consider the following graph:

This can be ordered in many ways, two of which are illustrated below:

For these orderings, the bandwidths of the nodes (in order) are 6, 6, 1, 4, 1, 1, 6, 6 giving an ordering bandwidth of 6, and 5, 3, 1, 4, 3, 5, 1, 4 giving an ordering bandwidth of 5.

Write a program that will find the ordering of a graph that minimises the bandwidth.

Input

Input will consist of a series of graphs. Each graph will appear on a line by itself. The entire file will be terminated by a line consisting of a single#. For each graph, the input will consist of a series of records separated by `;'. Each record will consist of a node name (a single upper case character in the the range `A' to `Z'), followed by a `:' and at least one of its neighbours. The graph will contain no more than 8 nodes.

Output

Output will consist of one line for each graph, listing the ordering of the nodes followed by an arrow (->) and the bandwidth for that ordering. All items must be separated from their neighbours by exactly one space. If more than one ordering produces the same bandwidth, then choose the smallest in lexicographic ordering, that is the one that would appear first in an alphabetic listing.

Sample input

A:FB;B:GC;D:GC;F:AGH;E:HD
#

Sample output

A B C F G D H E -> 3

枚举全排列,遇到nowmin > _min的情况就剪掉。

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索nodes
, graph
, and
, of
, The
that
,以便于您获取更多的相关知识。

时间: 2024-12-02 19:29:21

UVa 140 Bandwidth:枚举全排列&剪枝搜索的相关文章

uva 140 - Bandwidth

点击打开链接 题目意思:给定n个节点,(n<=8),节点的编号为A-Z 来表示,要求找到一个节点的序列,使得该序列最大的节点的Bandwidth为所有序列中的最小值,(节点的Bandwidth是指和它所连接的点中和它距离最大的值). 解题思路:由于最多只有8个节点,那么可以枚举这个解空间的所有情况,然后找到其中的最有解并且记录下它的节点顺序,那么我们可以通过求全排列的方法去一一枚举这些排列 代码: #include <iostream> #include <cstdio> #

UVa 140:Bandwidth

题目链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=108&page=show_problem&problem=76 类型: 回溯 原题: Given a graph (V,E) where V is a set of nodes and E is a set of arcs in VxV, and an ordering on the elements in

UVa 11218 KTV (枚举&amp;amp;位运算)

11218 - KTV Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=112&page=show_problem&problem=2159 One song is extremely popular recently, so you and your friends decided to sing it in KT

UVa 657:The die is cast 搜索专题

题目链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=105&page=show_problem&problem=598 题目类型: 搜索 样例输入: 30 15 .............................. .............................. ...............*.............. ...****

UVa 529:Addition Chains ,迭代加深搜索+减枝

题目链接: UVA :http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=470 POJ : http://poj.org/problem?id=2248 类型: 回溯, 迭代加深搜索, 减枝 原题: An addition chain for n is an integer sequence with the f

算法题:UVA 11008 Antimatter Ray Clearcutting(记忆化搜索+位运算)

Problem E Antimatter Ray Clearcutting Input: Standard Input Output: Standard Output It's year 2465, and you are the Chief Engineer for Glorified Lumberjacks Inc. on planet Trie. There is a number of trees that you need to cut down, and the only weapo

算法题:UVA 10626 Buying Coke(dp + 记忆化搜索)

I often buy Coca-Cola from the vending machine at work. Usually I buy several cokes at once, since my working mates also likes coke. A coke in the vending machine costs 8 Swedish crowns, and the machine accept crowns with the values 1, 5 and 10. As s

codeforce Pashmak and Buses(dfs枚举)

/* 题意:n个同学,k个车, 取旅游d天! 要求所有的学生没有两个或者两个以上的在同一辆车上共同带d天! 输出可行的方案! 对于d行n列的矩阵,第i行第j列表示的是第i天第j个同学所在的车号! 也就是保证所有行不全相同,即每一列都是不相同的! 如果每一列都不相同就是表示第j个同学(第j列)在这d天中不会和其他同学(列)在这d天中 都在同一辆车中! 思路:对于每一列我们枚举d天该学生所在的车号!它的下一列只保证有一个元素和它不同就行了!依次下去! 还有一共有 d 个位置来填充车号(1....k)

采用 部分索引、表达式索引 提高搜索效率

标签 PostgreSQL , partial index , 部分索引 , 表达式索引 , 复合索引 , gist_btree混合索引 , 空间索引 背景 在现实场景中,经常有搜索的需求,例如搜索附近的店铺,搜索通常会有一些搜索的附带条件,例如搜索附近的美食类店铺,加油站等. 这里实际上涉及两类搜索需求,一类是距离,一类是属性. 如果将属性枚举掉,那么搜索时可以变成只按距离搜索.建立空间索引即可. 而如果属性无法枚举,那么需要同时搜索空间和属性,可以建立 "空间+属性" 的"