当前位置:网站首页>L'épée leetcode fait référence au chemin leetcode de l'offre II 091 pour peindre la maison [planification dynamique] heroding
L'épée leetcode fait référence au chemin leetcode de l'offre II 091 pour peindre la maison [planification dynamique] heroding
2022-06-25 04:16:00 【Heroding23】
Comment résoudre le problème:
Un problème très fondamental de programmation dynamique,Peut même être donné directement dans la questioncostsSur la base de,Prends ça.costsEn tant que tableau de transition d'état,cost[i][0]Apparemment par le passéi-1De1Et2Couleur,cost[i][1]Etcost[i][2]C'est pareil.,Donc toujours prendre la somme minimale de chaque état,Il suffit de revenir,Les codes sont les suivants::
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]));
}
};
边栏推荐
- 95% 程序员都在这里摸鱼……
- Cesium drag 3D model
- “语法糖”——我的编程新知
- 【组队学习】SQL编程语言笔记——Task04
- Openmmlab environment configuration
- 长沙“求才”:“下力气”与“出实招”并进,“快发展”和“慢生活”兼得
- JS tool function, self encapsulating a throttling function
- 讲座记录《惯性导航的新应用——惯性测量》
- [proteus simulation] Arduino uno key controls the flashing increase / decrease display of nixie tube
- Jilin University 22 spring March new development English comprehensive course (I) assignment assessment-00080
猜你喜欢
Crawl Sina Weibo fans
讲座记录《多种空间大地测量技术的数据处理方法和应用》
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
小心被偷脸!天天用的人脸识别风险原来这么多?
Turn 2D photos into 3D models to see NVIDIA's new AI "magic"!
Zoran community
NFT Insider #63:The Sandbox与时代杂志达成合作,YGG成立西班牙subDAO
Crawler grabs the idea of reading on wechat
Flutter FittedBox组件
How to install opencv? Opencv download installation tutorial
随机推荐
1280_ C language to find the average value of two unsigned integer
Jilin University 22 spring March "automatic control principle" work assessment-00050
Upgrade cmake
2022-06-21-Flink-49(一. SQL手册)
2022-06-21-flink-49 (I. SQL manual)
数学分析_笔记_第3章:极限
Simple integration of client go gin -update
【Proteus仿真】Arduino UNO按键控制数码管闪烁增/减显示
Development of trading system (II) -- market data
Cesium 加载显示热力图
智慧风电:数字孪生 3D 风机智能设备运维
Lecture record: history and development of strapdown inertial navigation solution
Siddhartha: the book of life can be regurgitated frequently
[kubernetes series] installation and use of Helm
《Missing Parts》NFT 作品集第 5 系列上线 The Sandbox 市场平台
1. Phase II of the project - user registration and login
Hello CTP (III) - CTP quotation API
Color NFT series representing diversity launched on the sandbox market platform
"Renaissance" in the digital age? The bottom digital collection makes people happy and sad
Crawl Sina Weibo fans