当前位置:网站首页>Swordsman Offer II 091. Paint the House
Swordsman Offer II 091. Paint the House
2022-08-07 06:32:00 【henujolly】
class Solution {
public:
int minCost(vector<vector<int>>& costs) {
int n=costs.size();
vector<vector<int>>dp(n,vector<int>(3,0));
dp[0][0]=costs[0][0];
dp[0][1]=costs[0][1];
dp[0][2]=costs[0][2];
for(int i=1;i<costs.size();i++){
for(int j=0;j<3;j++){
dp[i][j]=min(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3])+costs[i][j];
}
}
int minn=INT_MAX;
for(int i=0;i<3;i++){
minn=min(minn,dp[n-1][i]);
}
return minn;
}
};
边栏推荐
- Docker 搭建redis集群
- Why NIO is more efficient than BIO
- Graphical LeetCode - 1408. String Matching in Arrays (Difficulty: Easy)
- OS模块中获取当前文件的绝对路径的相关方法
- R语言之朴素贝叶斯方法实现对垃圾邮件的分类
- 2022山东省安全员C证考试练习题及模拟考试
- This beta version of Typora is expired
- [Problem record] A bloody case caused by filter, how to locate the problem of upstream link, problem troubleshooting and sharing of positioning ideas
- [Array Questions] LeetCode 969. Pancake Sorting
- Baidu Cloud Deployment
猜你喜欢
随机推荐
cron 表达式
Taro 路由跳转预加载
grid grid layout
数组去重的几种办法
LeetCode 628. Maximum Product of Three Numbers
[Problem record] A bloody case caused by filter, how to locate the problem of upstream link, problem troubleshooting and sharing of positioning ideas
图论与网络模型——基于R
VoLTE基础自学系列 | 什么是VoLTE中的透明数据及非透明数据?
leetcode 110. 平衡二叉树
通过定位实现评论弹幕效果
R语言结合并行计算的实例一文讲懂环境
@Async注解的使用方法
TRACE32——内存填充测试Data.Pattern
MySQL - 索引优化
【专栏】RPC系列(理论)-协议与序列化
VoLTE基础自学系列 | RTP及RTCP协议原理
LeetCode points to Offer 24. Reverse linked list
R语言sys函数系列(一)
2022 8.3模拟
标签:对顶堆









