Poj1129 channel allocation dyeing problem

Source: Internet
Author: User

Description

When a radio station is broadcasting over a very large area, repeaters are used to retransmit the signal so that every extends er 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 shoshould be minimized. 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. for example, ten repeaters wocould 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. 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 valid Ric relationship; if A is adjacent to B, then B is necessarily adjacent to. 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 (could t 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

2A:B:4A:BCB:ACDC:ABDD:BC4A:BCDB:ACDC:ABDD:ABC0

Sample output

1 channel needed.3 channels needed.4 channels needed. problem Model: A connected graph is provided. Each letter represents a region. The right side of each line of the colon represents the region connected to the region. The adjacent area must be filled with different colors. Fill in at least several color codes:
# Include <iostream> # include <cstdio> # include <cstring> # include <cmath> # include <algorithm> using namespace STD; int map [30] [30]; // whether to connect int color [30]; // the nth color int ans in this region; int TT, T; bool OK (int A, int B) {for (INT I = 0; I <t; I ++) {If (Map [I] [a] = 1 & B = color [I]) // If the connected area has a color of type B, return false;} return true;} void DFS (int A, int colornum) cannot be specified in the area) {If (TT = 1) return; if (a> = T) {TT = 1; return;} For (INT I = 1; I <= colornum; I ++) {If (OK (A, I) {color [a] = I; DFS (a + 1, colornum ); // fill in the next region color [a] = 0 ;}} if (TT = 0) {ans ++; DFS (A, colornum + 1 ); // Add a color before filling} int main () {char Q [55]; int m, n, I, J, K; while (CIN> T & T) {TT = 0; memset (color, 0, sizeof (color); memset (MAP, 0, sizeof (MAP )); for (j = 1; j <= T; j ++) {scanf ("% s", q); for (I = 2; I <strlen (Q ); I ++) {map [Q [0]-'a'] [Q [I]-'a'] = 1 ;}} ans = 1; DFS (0, 1 ); if (ANS = 1) printf ("1 channel needed. \ n "); // pay attention to the singular and plural else printf (" % d channels needed. \ n ", ANS);} return 0 ;}


Brute force search ..

Poj1129 channel allocation dyeing problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.