思路:将4种flip作为4种状态,1,2,3,4可知1+2=3,1+3=2,2+3=1,因此共有1,2,3,4,1+4,2+4,3+4,initial这8种状态,且m>=3,n>=3时可满足,其余情况只需要分别判断。
class Solution(object):
def flipLights(self, n, m):
"""
:type n: int
:type m: int
:rtype: int
"""
if n==0:
return 0
if m==0:
return 1
if n==1:
return 2
if n==2 and m==1:
return 3
if n==2:
return 4
if m==1:
return 4
if m==2:
return 7
else:
return 8