Maximum Students Taking Exam

Given a classroom seating arrangement, place the maximum number of students so that no two students can cheat. Students cannot sit in broken seats, and they cannot sit adjacent horizontally or diagonally to another student in the row above. Pattern focus: Profile DP. Process the classroom row by row and represent each row by a bitmask of occupied seats.

Input Format

seats = classroom seat grid

Output Format

maximum number of students that can be seated

Constraints

  • 1 <= seats.length <= 8
  • 1 <= seats[i].length <= 8
  • seats contains '.' for good seats and '#' for broken seats

Examples

Example 1:

Input:

seats = [[".","."],[".","."]]

Output:

2

Explanation:

Place one student in each row in the same column to avoid conflicts.

Example 2:

Input:

seats = [[".","#","."],[".",".","."]]

Output:

4

Explanation:

One valid arrangement seats 2 students in the first row and 1 in the second row.

Example 3:

Input:

seats = [[".",".",".","."]]

Output:

2

Explanation:

In a single row, students must not sit next to each other.

Loading...
Maximum Students Taking Exam - Dp Advanced