当前位置:网站首页>Leetcode points to the leetcode road of offering II 091 house painting [dynamic planning] heroding
Leetcode points to the leetcode road of offering II 091 house painting [dynamic planning] heroding
2022-06-25 04:16:00 【HERODING23】

Their thinking :
A very basic dynamic programming problem , It can even be given directly in the question costs On the basis of , hold costs As an array of state transitions ,cost[i][0] Obviously, it was before i-1 Of 1 and 2 Color dependent ,cost[i][1] and cost[i][2] It's the same thing , So always take the minimum sum of each state , Return to , The code is as follows :
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]));
}
};
边栏推荐
- Mysql的order by
- 1.初识半音阶口琴
- opencv怎么安装?opencv下载安装教程
- Error 1062 is reported during MySQL insertion, but I do not have this field.
- acmStreamOpen返回值问题
- [proteus simulation] Arduino uno key controls the flashing increase / decrease display of nixie tube
- PHP code audit 1 - php Ini
- Turn 2D photos into 3D models to see NVIDIA's new AI "magic"!
- Windows 2003 64 bit system PHP running error: 1% is not a valid Win32 Application
- 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
猜你喜欢

Where is the red area of OpenCV?

地方/園區產業規劃之 “ 如何進行產業定比特 ”

Error 1062 is reported during MySQL insertion, but I do not have this field.

"Grammar sugar" -- my new programming knowledge

《Missing Parts》NFT 作品集第 5 系列上线 The Sandbox 市场平台

Crawler grabs the idea of reading on wechat

Hello CTP (II) -- Introduction to CTP

Development of trading system (III) - risk control system

client-go gin的简单整合十-Update

讲座记录《捷联惯导解算的历史及发展》
随机推荐
NFT Insider #63:The Sandbox与时代杂志达成合作,YGG成立西班牙subDAO
Watch out for the stolen face! So many risks of face recognition used every day?
MySQL modifies and deletes tables in batches according to the table prefix
数学分析_笔记_第3章:极限
[proteus simulation] Arduino uno key controls the flashing increase / decrease display of nixie tube
Error 1062 is reported during MySQL insertion, but I do not have this field.
[kubernetes series] installation and use of Helm
"Renaissance" in the digital age? The bottom digital collection makes people happy and sad
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)
冷热酸甜、想成就成?冷酸灵母公司登康口腔欲在深交所主板上市
Hello CTP (II) -- Introduction to CTP
5 key indicators of SEO: ranking + traffic + session + length of stay + bounce rate
Mysql的order by
Development of trading system (I) -- Introduction to trading system
How many images can opencv open?
Lecture record: history and development of strapdown inertial navigation solution
[harmony OS] [ark UI] basic ETS context operations
cesium 图形标注圆形、正方形、多边形、椭圆等
地方/園區產業規劃之 “ 如何進行產業定比特 ”
【LeetCode】22. 括号生成