当前位置:网站首页>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;
}
}
边栏推荐
- Binary tree sorting (C language, int type)
- Mortgage Calculator
- Dom4j遍历和更新XML
- LeetCode 1089. 复写零
- Dom4j traverses and updates XML
- 状态压缩DP AcWing 91. 最短Hamilton路径
- How to delete CSDN after sending a wrong blog? How to operate quickly
- Summary of methods for counting the number of file lines in shell scripts
- 即时通讯IM,是时代进步的逆流?看看JNPF怎么说
- Low code momentum, this information management system development artifact, you deserve it!
猜你喜欢

20220630 learning clock in

Gaussian elimination acwing 883 Gauss elimination for solving linear equations

记忆化搜索 AcWing 901. 滑雪

too many open files解决方案

XPath实现XML文档的查询

LeetCode 515. 在每个树行中找最大值

即时通讯IM,是时代进步的逆流?看看JNPF怎么说

LeetCode 715. Range 模块
![[concurrent programming] explicit lock and AQS](/img/5f/a80751a68726f53d11133810f454a3.jpg)
[concurrent programming] explicit lock and AQS

Query XML documents with XPath
随机推荐
Sword finger offer II 029 Sorted circular linked list
Concurrent programming (III) detailed explanation of synchronized keyword
Discussion on enterprise informatization construction
22-06-28 西安 redis(02) 持久化机制、入门使用、事务控制、主从复制机制
[concurrent programming] concurrent security
[rust notes] 08 enumeration and mode
Life cycle of Servlet
Deep parsing JVM memory model
传统企业数字化转型需要经过哪几个阶段?
Binary tree sorting (C language, char type)
Baidu editor ueeditor changes style
Binary to decimal, decimal to binary
cres
Slice and index of array with data type
URL backup 1
数字化管理中台+低代码,JNPF开启企业数字化转型的新引擎
20220630学习打卡
Arbre DP acwing 285. Un bal sans patron.
How to use Jupiter notebook
Low code momentum, this information management system development artifact, you deserve it!