1349. Maximum Students Taking Exam
https://leetcode.com/problems/maximum-students-taking-exam/
Last updated
Was this helpful?
https://leetcode.com/problems/maximum-students-taking-exam/
Last updated
Was this helpful?
Given a m * n
matrix seats
that represent seats distributions in a classroom. If a seat is broken, it is denoted by '#'
character otherwise it is denoted by a '.'
character.
Students can see the answers of those sitting next to the left, right, upper left and upper right, but he cannot see the answers of the student sitting directly in front or behind him. Return the maximum number of students that can take the exam together without any cheating being possible..
Students must be placed in seats in good condition.
Example 1:
Example 2:
Example 3:
Constraints:
seats
contains only characters '.' and'#'.
m == seats.length
n == seats[i].length
1 <= m <= 8
1 <= n <= 8
由#和.组成的矩阵,当左,右,左上和右上没有放置过人且当前位置为.时,可以放置一个人,问最多能放置多少人。当前行的放置状态只取决于上一行的状态,每一行可能有2^N个状态,因此用N位的bitvec encode状态。dp[i][state]表示前i行且第i行状态为state时最多能放置多少人。对每行做遍历并遍历第i行所有可能的状态,当状态满足左和右没有放置过人且是『.』时,再遍历上一行所有可能的状态,当满足左上和右上条件后统计可放置人数作为dp[i][state]。
参考自这。