Channel Allocation
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 15546   Accepted: 7871

Description

When a radio station is broadcasting over a very large area, repeaters are used to retransmit the signal so that every receiver has a strong signal. However, the channels used by each repeater must be carefully chosen so that nearby repeaters do not interfere with one another. This condition is satisfied if adjacent repeaters use different channels.

Since the radio frequency spectrum is a precious resource, the number of channels required by a given network of repeaters should be minimised. You have to write a program that reads in a description of a repeater network and determines the minimum number of channels required.

Input

The input consists of a number of maps of repeater networks. Each map begins with a line containing the number of repeaters. This is between 1 and 26, and the repeaters are referred to by consecutive upper-case letters of the alphabet starting with A. For example, ten repeaters would have the names A,B,C,...,I and J. A network with zero repeaters indicates the end of input.

Following the number of repeaters is a list of adjacency relationships. Each line has the form:

A:BCDH

which indicates that the repeaters B, C, D and H are adjacent to the repeater A. The first line describes those adjacent to repeater A, the second those adjacent to B, and so on for all of the repeaters. If a repeater is not adjacent to any other, its line has the form

A:

The repeaters are listed in alphabetical order.

Note that the adjacency is a symmetric relationship; if A is adjacent to B, then B is necessarily adjacent to A. Also, since the repeaters lie in a plane, the graph formed by connecting adjacent repeaters does not have any line segments that cross.

Output

For each map (except the final one with no repeaters), print a line containing the minumum number of channels needed so that no adjacent channels interfere. The sample output shows the format of this line. Take care that channels is in the singular form when only one channel is required.

Sample Input

2
A:
B:
4
A:BC
B:ACD
C:ABD
D:BC
4
A:BCD
B:ACD
C:ABD
D:ABC
0

Sample Output

1 channel needed.
3 channels needed.
4 channels needed.

POJ 1129 Channel Allocation DFS 回溯的更多相关文章

  1. poj 1129 Channel Allocation ( dfs )

    题目:http://poj.org/problem?id=1129 题意:求最小m,使平面图能染成m色,相邻两块不同色由四色定理可知顶点最多需要4种颜色即可.我们于是从1开始试到3即可. #inclu ...

  2. 迭代加深搜索 POJ 1129 Channel Allocation

    POJ 1129 Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14191   Acc ...

  3. POJ 1129 Channel Allocation(DFS)

    Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13173   Accepted: 67 ...

  4. POJ 1129 Channel Allocation 四色定理dfs

    题目: http://poj.org/problem?id=1129 开始没读懂题,看discuss的做法,都是循环枚举的,很麻烦.然后我就决定dfs,调试了半天终于0ms A了. #include ...

  5. poj 1129 Channel Allocation(图着色,DFS)

    题意: N个中继站,相邻的中继站频道不得相同,问最少需要几个频道. 输入输出: Sample Input 2 A: B: 4 A:BC B:ACD C:ABD D:BC 4 A:BCD B:ACD C ...

  6. poj 1129 Channel Allocation

    http://poj.org/problem?id=1129 import java.util.*; import java.math.*; public class Main { public st ...

  7. poj 1154 letters (dfs回溯)

    http://poj.org/problem?id=1154 #include<iostream> using namespace std; ]={},s,r,sum=,s1=; ][]; ...

  8. PKU 1129 Channel Allocation(染色问题||搜索+剪枝)

    题目大意建模: 一个有N个节点的无向图,要求对每个节点进行染色,使得相邻两个节点颜色都不同,问最少需要多少种颜色? 那么题目就变成了一个经典的图的染色问题 例如:N=7 A:BCDEFG B:ACDE ...

  9. POJ 1321 棋盘问题 (DFS + 回溯)

    题目链接:http://poj.org/problem?id=1321 题意:中文题目,就不多说了...... 思路: 解题方法挺多,刚开始想的是先从N行中选择出来含有“#”的K行,再在这K行中放置K ...

随机推荐

  1. 深入浅出时序数据库之预处理篇——批处理和流处理,用户可定制,但目前流行influxdb没有做

    时序数据是一个写多读少的场景,对时序数据库以及数据存储方面做了论述,数据查询和聚合运算同样是时序数据库必不可少的功能之一.如何支持在秒级对上亿数据的查询分组聚合运算成为了时序数据库产品必须要面对的挑战 ...

  2. codeforces 931E Logical Expression dp

    time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standa ...

  3. 【POJ 1964】 City Game

    [题目链接] http://poj.org/problem?id=1964 [算法] 记f[i]表示第i行最多向上延伸的行数 然后,对于每一行,我们用单调栈计算出这一行向上延伸的最大矩形面积,取最大值 ...

  4. JavaScript表格搜索高亮功能模拟

    在网页表格中模拟excle的搜索高亮显示功能.当在搜索框中输入需要的姓名时,若表格中存在对应的数据,则该表格背景色变为黄色. 下面为表的HTML源码: <!doctype html> &l ...

  5. protobuf 编译 java js文件详解

    首先下载protobuf.exe 下载地址:https://download.csdn.net/download/qq_34756156/10220137 MessageBody.proto synt ...

  6. # Nginx常见问题

    try_files的使用 按顺序检查文件是否 存在 location /{ try_files $uri $uri/ /index.php } 解析:在/下寻找$uri,如果没有找到,则去找$uri/ ...

  7. Bootstrap3.0的栅格布局系统实现原理

    这个标题取的有点奇怪,怪我翻译的有问题吧.英文学平有限,有道词典和google翻译齐上阵是必须的.还好翻译的不是小说,对于技术文章,还是能勉强翻过来的. 本文主要讲解了Bootstrap3.0的栅格布 ...

  8. ViewPager循环滚动

    一.先写个适配器 public class MyPagerAdapter extends PagerAdapter { /** * 上下文 */ private Context context; /* ...

  9. set statistics profile on实例

    set statistics profile on实例 1.SQL语句实例   SQL 代码   复制 SET STATISTICS PROFILE ON GO SELECT COUNT(b.[Sal ...

  10. 使用Visio—UML画类图

    在一个VS工程中,由于类的个数较多,而参数描述不是特别清晰.若此工程的生命周期较长,则有必要对工程进行完整分析,给出完整的文档.需要画出类图,并对每个成员进行详细描述. 一.画出类图 在VIsio中, ...