Movie Theater Seating
Time limit2sMemory limit64 MB
Decide whether S solo guests and C couples fit into R rows of 8 seats with reserved seats while keeping neighbors and front seats empty.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Bit manipulation, Backtracking
- Solved
- No attempts yet
Problem
Haebin runs a movie theater with rows of 8 seats each. Some seats are already reserved, and three kinds of guests walk in.
- guests who reserved a seat
- solo guests who did not reserve
- couples who did not reserve (a couple wants to sit side by side)
A guest who reserved simply takes the reserved seat. Haebin has to seat the remaining solo guests and couples under these rules.
- A solo guest only takes a seat that is not reserved.
- A solo guest hates having anyone beside them in the same row.
- A solo guest hates having anyone in the seat directly in front of them.
- A couple takes two adjacent seats in the same row, and neither seat is reserved.
- Other than the partner, a couple hates having anyone beside them in the same row.
- A couple hates having anyone in the seats directly in front of them.
The seat directly in front of a given seat is the seat in the same column of the row immediately ahead. The word anyone in these rules covers reserved guests, solo guests and couples alike. Reserved guests are easygoing and ignore every rule above.
Given the reserved seats, the number of solo guests and the number of couples , decide whether the solo guests and the couples can all be seated under the rules.
Input
The first line contains the number of test cases ().
The first line of each test case contains three integers , and (, , ). The next lines correspond to the seat rows from the front row of the theater to the back row. Each line is a binary string of length 8, where 0 is a seat that is not reserved and 1 is a reserved seat.
Output
For each test case, print YES on its own line if everyone can be seated under the rules, and NO otherwise.