logo AlgoBeat OnlineJudge
登录 注册

#10400. [Topcoder 6407] LightSwitches

内存限制:512 MiB 时间限制:1000 ms 标准输入输出
题目类型:传统 评测方式:文本比较
上传者: Carey_chen HCl

题目描述

LightSwitches

Problem Statement

In a ballroom, there are some light bulbs and some switches that control those bulbs. However, the switches and the bulbs are not related in a logical way. Each switch is connected to a subset of the bulbs, and when a switch is flipped, all the bulbs connected to that switch change state (the ones that were off are turned on, and the ones that were on are turned off). Bulbs that are not connected to the flipped switch remain as they were. The states of all the bulbs in the room can be described as a configuration of lights. If there are N bulbs, there are 2N possible configurations. Two configurations are distinct if a bulb in one configuration has a different state than that same bulb in the other configuration. You will be given the connections between the switches and bulbs as a String[] switches. The jth character of the ith element of switches is 'Y' if the ith switch is connected to the jth bulb, and 'N' otherwise. All the bulbs are initially off. Return the number of distinct configurations of lights that can be achieved using this setup.

Definition

  • Class: LightSwitches
  • Method: countPossibleConfigurations
  • Parameters: String[]
  • Returns: long
  • Method signature: long countPossibleConfigurations(String[] switches)
  • (be sure your method is public)

Constraints

  • switches will have between 1 and 50 elements, inclusive.
  • Each element of switches will have exactly N characters, where N is between 1 and 50, inclusive.
  • Each character of each element of switches will be 'Y' or 'N'.

Examples

Example 1 Input

4
YYN
NNY
YYY
NNN

Example 1 Output

4

Example 1 Explanation

In this example, there are three bulbs and four switches. The first switch is connected to the first two lights, the second switch is connected to the third light, the third switch is connected to all three lights, and the fourth switch is connected to nothing. The possible configurations are (- for OFF and + for ON):

      • The initial configuration.
      • This can be achieved by flipping the first switch.
      • This can be achieved by flipping the second switch.
      • This can be achieved by flipping the first switch and then the second switch.

Example 2 Input

1
NNNNYYYNYYNYYYYYNYY

Example 2 Output

2

Example 2 Explanation

There are only two possible configurations here - the initial configuration where all the bulbs are off, and the configuration that results from flipping the switch once.

Example 3 Input

30
YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
NYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN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NNNNNNNNN
NNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNN
NNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNN
NNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNN
NNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNN
NNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNN
NNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNN
NNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNN
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNN

Example 3 Output

1073741824

Example 3 Explanation

Each of the first 30 bulbs can be turned on and off individually while the remaining 20 bulbs are impossible to turn on. Any combination of states among the first 30 bulbs is possible, so the number of configurations is 230.

Example 4 Input

5
YNNNN
NYNNN
NNYNN
NNNYN
NNNNY

Example 4 Output

32

Example 5 Input

6
NYNYNYN
YNYNYNY
YYNNNYN
NNNYNYN
YYYYYNN
YNNNNYN

Example 5 Output

32

Copyright

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.

Source

2006- SRM 306 - Division I, Level Two