Perhaps I am just misunderstanding the problem, but for the example of n=4 fence posts and k=2 colors, the OJ indicates that the output should be 10.
Can someone help me understand why this is the case?
Lets say the colors are red (R) and blue (B). The possible colorings are:
RRBR RBBR RBRR
BBRB BRRB BRBB
Where am I undercounting?
Thanks. I've misunderstood the problem then.
"You have to paint all the posts such that no more than two adjacent fence posts have the same color."
I think the problem should be reworded. The above seems to be imply that two adjacent fence posts to me means one pair of adjacent posts so BBRR and RRBB have two pairs of adjacent posts and thus should not be counted.
@jim11 Thanks! I made the same mistakes
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.