【LeetCode】粉刷房子

粉刷房子

链接: 粉刷房子

题目描述

算法分析

编程代码

cpp 复制代码
**class Solution {
public:
    int minCost(vector<vector<int>>& costs) {
        int n = costs.size();
        vector<vector<int>> dp(n+1,vector<int>(3));
        for(int i = 1;i<=n;++i)
        {
            dp[i][0] = min(dp[i-1][1],dp[i-1][2]) + costs[i-1][0];
            dp[i][1] = min(dp[i-1][0],dp[i-1][2]) + costs[i-1][1];
            dp[i][2] = min(dp[i-1][1],dp[i-1][0]) + costs[i-1][2];
        }
        return min(dp[n][0],min(dp[n][1],dp[n][2]));
    }
};**
相关推荐
Liangwei Lin16 小时前
LeetCode 74. 搜索二维矩阵
算法·leetcode·矩阵
mask哥1 天前
力扣算法java实现汇总整理(上)
java·算法·leetcode
流年如夢1 天前
栈和列队(LeetCode)
数据结构·算法·leetcode·链表·职场和发展
星星码️1 天前
LeetCode刷题简单篇之反转字母
c++·算法·leetcode
sheeta19982 天前
LeetCode 每日一题笔记 日期:2026.05.10 题目:2770. 达到末尾下标所需的最大跳跃次数
笔记·算法·leetcode
shehuiyuelaiyuehao2 天前
算法21,搜索插入位置
python·算法·leetcode
_深海凉_2 天前
LeetCode热题100-回文链表
算法·leetcode·链表
小雅痞2 天前
[Java][Leetcode middle] 54. 螺旋矩阵
java·leetcode·矩阵
pursuit_csdn2 天前
力扣周赛 501
算法·leetcode·职场和发展
AbandonForce2 天前
LeetCode 滑动窗口个人思路详解
算法·leetcode·职场和发展