当前位置:网站首页>Sword finger offer II 091 Paint the house
Sword finger offer II 091 Paint the house
2022-07-03 09:02:00 【Sasakihaise_】
The finger of the sword Offer II 091. Paint the house

【DP】 Open one dp[n+1][3] Array of , For the first i The second house j Medium color , There can be a second i-1 The minimum value of two colors outside two houses .
class Solution {
//dp 1:21
public int minCost(int[][] costs) {
int n = costs.length;
int max = 1 << 30, ans = max;
int[][] dp = new int[n + 1][3];
for(var i = 1; i <= n; i++){
for(var j = 0; j < 3; j++){
int min = max;
for(var k = 0; k < 3; k++){
if(k == j) continue;
else min = Math.min(min, dp[i - 1][k]);
}
dp[i][j] = min + costs[i - 1][j];
if(i == n){
ans = Math.min(dp[i][j], ans);
}
}
}
return ans;
}
}
边栏推荐
- SQL statement error of common bug caused by Excel cell content that is not paid attention to for a long time
- 推荐一个 yyds 的低代码开源项目
- Monotonic stack -503 Next bigger Element II
- [concurrent programming] atomic operation CAS
- On the difference and connection between find and select in TP5 framework
- LeetCode 438. 找到字符串中所有字母异位词
- LeetCode 1089. Duplicate zero
- 传统办公模式的“助推器”,搭建OA办公系统,原来就这么简单!
- Parameters of convolutional neural network
- In the digital transformation, what problems will occur in enterprise equipment management? Jnpf may be the "optimal solution"
猜你喜欢

LeetCode 324. 摆动排序 II

JS ternary operator - learning notes (with cases)

拯救剧荒,程序员最爱看的高分美剧TOP10

Monotonic stack -84 The largest rectangle in the histogram

Concurrent programming (VI) ABA problems and solutions under CAS

Binary tree sorting (C language, char type)

Monotonic stack -42 Connect rainwater

AcWing 785. Quick sort (template)

Notes and bugs generated during the use of h:i:s and y-m-d

Six dimensional space (C language)
随机推荐
createjs easeljs
20220630学习打卡
On the setting of global variable position in C language
Es8 async and await learning notes
URL backup 1
Using variables in sed command
Binary to decimal, decimal to binary
How to use Jupiter notebook
Mortgage Calculator
传统企业数字化转型需要经过哪几个阶段?
常见渗透测试靶场
Binary tree traversal (first order traversal. Output results according to first order, middle order, and last order)
XPath实现XML文档的查询
[concurrent programming] explicit lock and AQS
The method of replacing the newline character '\n' of a file with a space in the shell
LeetCode 57. 插入区间
Common penetration test range
Concurrent programming (VI) ABA problems and solutions under CAS
Too many open files solution
LeetCode 75. 颜色分类