Lintcode 房屋染色
来源:互联网 发布:js 绘制小球运动轨迹 编辑:程序博客网 时间:2024/05/02 22:28
这里有n个房子在一列直线上,现在我们需要给房屋染色,分别有红色蓝色和绿色。每个房屋染不同的颜色费用也不同,你需要设计一种染色方案使得相邻的房屋颜色不同,并且费用最小。
费用通过一个nx3 的矩阵给出,比如cost[0][0]表示房屋0染红色的费用,cost[1][2]表示房屋1染绿色的费用
class Solution {public: /** * @param costs n x 3 cost matrix * @return an integer, the minimum cost to paint all houses */ int minCost(vector<vector<int>>& costs) { // Write your code here if(costs.size()==0) { return 0; } int m = costs.size()-1; for(int i = 1; i <= m; i++){ costs[i][0] += min(costs[i-1][1], costs[i-1][2]); costs[i][1] += min(costs[i-1][0], costs[i-1][2]); costs[i][2] += min(costs[i-1][0], costs[i-1][1]); } return min(min(costs[m][0], costs[m][1]), costs[m][2]); }};
阅读全文
0 0
- LintCode: 房屋染色 II
- LintCode:房屋染色 i
- Lintcode 房屋染色
- LintCode 房屋染色II
- lintcode -- 房屋染色
- LintCode:M-房屋染色
- lintcode房屋染色
- 房屋染色-LintCode
- 房屋染色 II-LintCode
- LINTCODE——房屋染色II
- 房屋染色
- 房屋染色
- 房屋染色
- LintCode-打劫房屋
- lintcode-打劫房屋
- LintCode-打劫房屋
- Lintcode打劫房屋
- lintcode ----打劫房屋
- 使用LaTeX方法
- ubuntu14.04 更改cmake版本
- @property
- Python数据类型的转换
- Qt5应用程序的部署
- Lintcode 房屋染色
- 输入挂
- 内部类
- 开脑洞,买买买网站的皮肤
- postgresql lsn
- 一款短小精致的SSH后门分析
- Scala基础入门(二) Scala下载、安装教程
- __future__
- Linux 常用基本命令 ping ifconfig