当前位置:网站首页>LeetCode 剑指Offer II 091 粉刷房子[动态规划] HERODING的LeetCode之路
LeetCode 剑指Offer II 091 粉刷房子[动态规划] HERODING的LeetCode之路
2022-06-25 03:54:00 【HERODING23】

解题思路:
非常基础的一道动态规划题,甚至可以直接在题中所给的costs基础上进行,把costs作为状态转移数组,cost[i][0]显然是由之前i-1的1和2颜色决定的,cost[i][1]和cost[i][2]也是同理,所以一直取每个状态的最小和,返回即可,代码如下:
class Solution {
public:
int minCost(vector<vector<int>>& costs) {
int n = costs.size();
for(int i = 1; i < n; 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(costs[n-1][0], min(costs[n-1][1], costs[n-1][2]));
}
};
边栏推荐
- web3.eth. Getpendingtransactions() returns null?
- AI quantitative transaction (I) -- Introduction to quantitative transaction
- [harmony OS] [arkui] ETS development graphics and animation drawing
- 讲座记录《惯性导航的新应用——惯性测量》
- 警惕超范围采集隐私-移动APP违规十宗罪
- Cesium graphic annotation circle, square, polygon, ellipse, etc
- Hot and cold, sweet and sour, want to achieve success? Dengkang oral, the parent company of lengsuanling, intends to be listed on the main board of Shenzhen Stock Exchange
- Trading system development (IV) - trading counter system
- On the self-cultivation of an excellent red team member
- 1.初识半音阶口琴
猜你喜欢
![[proteus simulation] Arduino uno key controls the flashing increase / decrease display of nixie tube](/img/28/33f3e9736a68439b5bcdc4e75c939c.png)
[proteus simulation] Arduino uno key controls the flashing increase / decrease display of nixie tube

1. first knowledge of chromatic harmonica

Watch out for the stolen face! So many risks of face recognition used every day?

cesium 图形标注圆形、正方形、多边形、椭圆等

Numpy NP tips: use OpenCV to interpolate and zoom the array to a fixed shape cv2 resize(res, dsize=(64, 64), interpolation=cv2. INTER_ CUBIC)

Simple integration of client go gin 11 delete

【openwrt】推荐一个国内开发的openwrt的版本,iStoreOS简介,非常好用,主要是做了一些优化。解决了汉化的问题。

讲座记录《惯性导航的新应用——惯性测量》

Trading system development (IV) - trading counter system

Development of trading system (VI) -- HFT high frequency trading
随机推荐
Development of trading system (I) -- Introduction to trading system
Hello CTP (III) - CTP quotation API
Hello CTP (V) -- CTP position calculation
Jilin University 22 spring March new development English comprehensive course (I) assignment assessment-00080
The 5th series of NFT works of missing parts was launched on the sandbox market platform
Development of trading system (VIII) -- Construction of low delay network
数学分析_笔记_第3章:极限
2D 照片变身 3D 模型,来看英伟达的 AI 新“魔法”!
Work assessment of Biopharmaceutics of Jilin University in March of the 22nd spring -00031
web3.eth. Getpendingtransactions() returns null?
驻波比计算方法
Cesium graphic annotation circle, square, polygon, ellipse, etc
Hello CTP (I) - basic knowledge of futures
小心被偷脸!天天用的人脸识别风险原来这么多?
虽然传统意义上的互联网早已不复存在,但这并不代表互联网早已消失不再
Russian Airi Research Institute, etc. | SEMA: prediction of antigen B cell conformation characterization using deep transfer learning
Where is the red area of OpenCV?
openmmlab-环境配置
论文阅读《LSD-SLAM: Large-Scale Direct Monocular SLAM》
Lecture record: history and development of strapdown inertial navigation solution