当前位置:网站首页>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]));
}
};
边栏推荐
- Russian Airi Research Institute, etc. | SEMA: prediction of antigen B cell conformation characterization using deep transfer learning
- 小心被偷脸!天天用的人脸识别风险原来这么多?
- [kubernetes series] installation and use of Helm
- Mathematical analysis_ Notes_ Chapter 3: limits
- Exercise: how difficult is it to simulate the blessing lottery two-color ball - China 500W grand prize? Just run the code.
- How much do you know about the use value of WMS warehouse management system
- Lecture record: new application of inertial navigation - inertial measurement
- 1、项目第二阶段——用户注册和登陆
- Hello CTP (IV) - CTP transaction API
- @RequestBody解决获取参数为null
猜你喜欢
WMS仓储管理系统的使用价值,你知道多少
Simple integration of client go gin 11 delete
BSC parsing input data of transaction
Interview with Mo Tianlun | ivorysql wangzhibin - ivorysql, an Oracle compatible open source database based on PostgreSQL
Siddhartha: the book of life can be regurgitated frequently
【Proteus仿真】Arduino UNO按键控制数码管闪烁增/减显示
How much do you know about the use value of WMS warehouse management system
【组队学习】SQL编程语言笔记——Task04
Hello CTP (II) -- Introduction to CTP
讲座记录《多种空间大地测量技术的数据处理方法和应用》
随机推荐
Development of trading system (IX) -- dark pool technology
2. play the chromatic harmonica
How to quickly deliver high-value software
Intel 13代酷睿首次露出真面目:68MB缓存提升明显
Color NFT series representing diversity launched on the sandbox market platform
(ultra detailed onenet TCP protocol access) arduino+esp8266-01s accesses the Internet of things platform, uploads real-time collected data /tcp transparent transmission (and how to obtain and write Lu
Work assessment of pharmacotherapeutics of Jilin University in March of the 22nd spring -00064
【openwrt】推荐一个国内开发的openwrt的版本,iStoreOS简介,非常好用,主要是做了一些优化。解决了汉化的问题。
General steps for QT compiling database plug-ins
Development of trading system (V) -- Introduction to Sinovel counter
【LeetCode】148. Sort linked list
"Grammar sugar" -- my new programming knowledge
Zoran community
2.吹响半音阶口琴
WMS仓储管理系统的使用价值,你知道多少
地方/园区产业规划之 “ 如何进行产业定位 ”
练习:仿真模拟福彩双色球——中500w巨奖到底有多难?跑跑代码就晓得了。
论文阅读《LSD-SLAM: Large-Scale Direct Monocular SLAM》
警惕超范围采集隐私-移动APP违规十宗罪
PHP代码审计2—这些函数必知必会