TopCoder problem "MovieSeating" used in SRM 483 (Division II Level Two)

Problem Statement

    Elly and some of her friends (possibly none) are going to the movies. Their company consists of numFriends people, including Elly. Since they don't want to be spread across the entire hall, they decided to sit either in the same row or in the same column (though not necessarily next to one another).

Your are given a String[] hall representing the layout of seats in the theater that are already taken. The j-th character of the i-th element of hall will be '#' if the seat at row i, column j is already taken and '.' if it is empty.

Return the number of different ways for Elly and her friends to choose numFriends different empty seats so that their seating requirement is fulfilled. Two ways are considered different if there exists a person in their company that will sit in different seats in these two ways.



Parameters:int, String[]
Method signature:long getSeatings(int numFriends, String[] hall)
(be sure your method is public)


-numFriends will be between 1 and 8, inclusive.
-hall will contain between 1 and 50 elements, inclusive.
-Each element of hall will contain between 1 and 50 characters, inclusive.
-All elements of hall will contain the same number of characters.
-Each character in hall will be either '.' or '#'.


{ ".#..",
  "...." }
Returns: 34
Here the movie hall has 3 rows and 4 columns. The second seat in the first row is taken, as well as the seats in the middle of the second row.
{ "..#",
  "..." }
Returns: 16
Elly and her friend can sit in two ways in the first row, they cannot sit in the second row, and they can sit in six ways in the third row. If they choose to sit in the same column, they can do it in six ways in the leftmost column, two ways in the middle column, and not in the rightmost column because there is only one seat.
{ "..####..", 
  "#.#.#.#." }
Returns: 0
There are enough places for the company, but since they want to sit in the same row or same column, none of the possible seatings satisfies them.
{ "........" }
Returns: 40320
Just enough seats for all of them.

Problem url:

Problem stats url:




PabloGilberto , ivan_metelsky , gojira_tc

Problem categories:

Simple Math