514. Paint Fence
来源:互联网 发布:录制视频软件手机 编辑:程序博客网 时间:2024/06/05 16:42
class Solution {public: /* * @param n: non-negative integer, n posts * @param k: non-negative integer, k colors * @return: an integer, the total number of ways */ int numWays(int n, int k) { // write your code here if (n==0) return 0; if (n==1) return k; if (n==2) return k*k; int x=k*(k-1),y=k; for (int i=3;i<=n;i++){ int tmp=x; x=(x+y)*(k-1); y=tmp; } return x+y; }};
阅读全文
0 0
- 514. Paint Fence
- Paint Fence
- Paint Fence
- **LeetCode-Paint Fence
- [leetcode 276] Paint Fence
- [LeetCode276]Paint Fence
- leetcode Paint Fence
- Paint Fence 栅栏涂色
- LeetCode 276. Paint Fence
- Paint fence and house
- LeetCode 276. Paint Fence
- 276. Paint Fence
- 514.Paint Fence-栅栏染色(容易题)
- LeetCode 题解(243) : Paint Fence
- lintcode paint-fence 栅栏染色
- 【编程】【leetcode】276 Paint Fence
- 【dp】leetcode 276. Paint Fence
- [leetcode] 276. Paint Fence 解题报告
- MySQL —— FOREING KEY(外键约束)
- 算法第16周Maximum Subarray[easy]
- iconfont
- 内存分析
- 推荐系统实践---第三章:推荐系统冷启动问题
- 514. Paint Fence
- docker搭建redis集群
- TCP
- 素数筛选法
- 二叉树的递归遍历与复制
- 电脑每次开机总是自动还原怎么回事?
- 2大侧拉框对比:DrawerLayout 和 SlidingMenu
- 从JVM角度阐述Java数据类型
- [Leetcode从零开刷]728. Self Dividing Numbers