码迷,mamicode.com
首页 > 其他好文 > 详细

[LintCode] Paint Fence 粉刷篱笆

时间:2016-04-30 13:01:23      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:

 

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.

Notice

n and k are non-negative integers.

Example
Given n=3, k=2 return 6

post 1, post 2, post 3
way1 0 0 1
way2 0 1 0
way3 0 1 1
way4 1 0 0
way5 1 0 1
way6 1 1 0

 

[LintCode] Paint Fence 粉刷篱笆

标签:

原文地址:http://www.cnblogs.com/grandyang/p/5448516.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!