Logo
(追記) (追記ここまで)

4481번 - Power Grid 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB105450.000%

문제

After the untimely demise of its previous tenant, you have found yourself promoted to the position of the new “chief architect” of the Death Star by none other than Lord Vader himself. Your have been tasked with designing the wiring system for distributing power throughout each sector of the Death Star. Knowing that your life depends on your success, you have decided to be extremely meticulous and exhaustively enumerate all valid wiring configurations so that you may choose the best one.

You are given a map of the Death Star, in the form of an m × n grid, whose cells correspond to sectors. Exactly one of the sectors in the map is a power station; the remaining sectors are all either living quarters or storage units. You have the option of placing a connection between any two non-storage sectors that are either vertically or horizontally adjacent. A valid wiring configuration is one such that:

  • Every living quarter sector is either directly or indirectly connected to the power station sector, and
  • As few connections are used as possible (i.e., removing any connection would result in disconnecting some living quarter from the power station).

For a given map, how many valid wiring configurations exist?

입력

The input will contain multiple test cases. Each test case begins with a single line containing a pair of integers m and n (where 1 ≤ m ≤ 8 and 1 ≤ n ≤ 8). The next m lines each contain n characters, representing the map of the Death Star. The map will contain exactly one sector marked as a power station (P); the remainder of the sections will be either living quarters (.) or storage units (#). You are guaranteed that there exists at least one valid wiring configuration. The end-of-input is denoted by a single line containing “0 0” and should not be processed.

출력

For each input test case, print the number of valid wiring configurations mod 1,000,000,000.

제한

예제 입력 1

2 2
..
.P
4 5
#####
#.P.#
#...#
#####
3 4
....
P#..
...#
6 6
######
##..##
#....#
#..P.#
##..##
######
0 0

예제 출력 1

4
15
31
768

힌트

출처

ICPC > Regionals > North America > Pacific Northwest Regional > 2009 Pacific Northwest Region Programming Contest K번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /