Leetcode 256. Paint House (Medium) (cpp)
来源:互联网 发布:拥有域名之后怎么建站 编辑:程序博客网 时间:2024/05/16 07:17
Leetcode 256. Paint House (Medium) (cpp)
Tag: Dynamic Programming
Difficulty: Medium
/*256. Paint House (Medium)There are a row of n houses, each house can be painted with one of the three colors: red, blue or green. The cost of painting each house with a certain color is different. You have to paint all the houses such that no two adjacent houses have the same color.The cost of painting each house with a certain color is represented by a n x 3 cost matrix. For example, costs[0][0] is the cost of painting house 0 with color red; costs[1][2] is the cost of painting house 1 with color green, and so on... Find the minimum cost to paint all houses.Note:All costs are positive integers.*/class Solution {public:int minCost(vector<vector<int>>& costs) {if (costs.size() == 0 || costs[0].size() == 0) {return 0;}for (int i = 1; i < costs.size(); i++) {for (int j = 0; j < 3; j++) {if (j == 0) {costs[i][0] += min(costs[i - 1][1], costs[i - 1][2]);}else if (j == 1) {costs[i][1] += min(costs[i - 1][0], costs[i - 1][2]);}else {costs[i][2] += min(costs[i - 1][0], costs[i - 1][1]);}}}return min(costs.back()[0], min(costs.back()[1], costs.back()[2]));}};
0 0
- Leetcode 256. Paint House (Medium) (cpp)
- LeetCode 256. Paint House
- LeetCode 256. Paint House
- Leetcode 213. House Robber II (Medium) (cpp)
- Leetcode 337. House Robber III (Medium) (cpp)
- Leetcode 256. Paint House & 265. Paint House II
- Medium 256题 Paint House
- [leetcode] 256. Paint House 解题报告
- LeetCode 256. Paint House(房子涂色)
- [Leetcode] 256. Paint House 解题报告
- Leetcode: Paint House
- Leetcode: Paint House II
- [Leetcode]Paint House
- [Leetcode]Paint House II
- *LeetCode-Paint House
- [LeetCode] Paint House
- [leetcode 256] Paint House
- [Leetcode 256]Paint House
- 优酷、腾讯视频播放器接口参数说明
- 石子合并问题
- php连接sqlserver
- Leetcode Largest Divisible Subset
- jquery正则表达式检测密码强度
- Leetcode 256. Paint House (Medium) (cpp)
- 免费工具集
- 工作空间目录
- PHP的imagefilledarc()函数参数详解
- 【读书笔记】Effective C++
- 基于Java Socket的聊天室使用说明书
- 独立任务调度问题
- Android模拟器不能上网问题
- 1-12