There is a fence with n posts, each post can be painted with one of the k colors.
You have to paint all the posts such that no more than two adjacent fence posts have the same color.
Return the total number of ways you can paint the fence.
Note:
n and k are non-negative integers.
一开始理解错“no more than two adjacent fence posts”了,以为是说总共最多只能有两个相邻的,题意应该是相邻的情况里只能是两个相邻,但是XXOO这种是允许的。
|
|