tag:blogger.com,1999:blog-4731036105252322780.post1947073251331721236..comments2024-03-01T02:55:58.951-08:00Comments on Buttercola: Leetcode: Paint Fence Butter is looking for a jobhttp://www.blogger.com/profile/01481083468821703855noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-4731036105252322780.post-21116243442608645972016-12-30T08:27:57.812-08:002016-12-30T08:27:57.812-08:00Thanks!,Thanks!,raaghttps://www.blogger.com/profile/05736726632048340227noreply@blogger.comtag:blogger.com,1999:blog-4731036105252322780.post-88308387071640787352016-05-06T02:18:32.127-07:002016-05-06T02:18:32.127-07:00Two possibilities for DP[i]
1. EndUpHavingSameColo...Two possibilities for DP[i]<br />1. EndUpHavingSameColorAsPrevious<br />- Which means, the last two should be different colors.<br />- Number of ways last two can have different colors, makes it eligible for having same color. <br />- Number of ways last two can have different colors = "EndUpHavingDifferentColorAsPrevious"<br />- Since we choose same color as previous, then the number of possibilities is just carried over. <br />- EndUpHavingSameColorAsPrevious[i] = EndUpHavingDifferentColorAsPrevious[i-1]<br /><br /><br />2. EndUpHavingDifferentColorAsPrevious<br />- Case - 1 : The last two can have same colors - and we choose K-1 other colors for each. .. ie, EndUpHavingSameColorAsPrevious[i-1] * (K-1)<br />- Case - 2 : The last two can have different colors - and we choose K-1 colors for each. <br />- EndUpHavingDifferentColorAsPrevious[i-1] * (K-1)<br />- EndUpHavingDifferentColorAsPrevious[i] = above two cases;<br /><br />TotalDP[i] = EndUpHavingSameColorAsPrevious[i] + EndUpHavingDifferentColorAsPrevious[i];Anonymoushttps://www.blogger.com/profile/15507829542455891062noreply@blogger.com