当前位置:网站首页>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;
}
}
边栏推荐
- [rust notes] 08 enumeration and mode
- Get the link behind? Parameter value after question mark
- too many open files解决方案
- 我們有個共同的名字,XX工
- Deeply understand the underlying data structure of MySQL index
- Complex character + number pyramid
- Binary tree sorting (C language, int type)
- 状态压缩DP AcWing 91. 最短Hamilton路径
- 注解简化配置与启动时加载
- Common DOS commands
猜你喜欢
数位统计DP AcWing 338. 计数问题
too many open files解决方案
Deep parsing JVM memory model
AcWing 785. 快速排序(模板)
Alibaba canaladmin deployment and canal cluster Ha Construction
Divide candy (circular queue)
Try to reprint an article about CSDN reprint
剑指 Offer II 091. 粉刷房子
Dom4j traverses and updates XML
传统企业数字化转型需要经过哪几个阶段?
随机推荐
Methods of checking ports according to processes and checking processes according to ports
Too many open files solution
低代码前景可期,JNPF灵活易用,用智能定义新型办公模式
Monotonic stack -503 Next bigger Element II
LeetCode 30. 串联所有单词的子串
LeetCode 871. 最低加油次数
Es8 async and await learning notes
Format - C language project sub file
Alibaba canaladmin deployment and canal cluster Ha Construction
Binary tree sorting (C language, char type)
Deep parsing (picture and text) JVM garbage collector (II)
常见渗透测试靶场
Discussion on enterprise informatization construction
Monotonic stack -42 Connect rainwater
php public private protected
Common DOS commands
LeetCode 324. 摆动排序 II
LeetCode 1089. Duplicate zero
The method for win10 system to enter the control panel is as follows:
How to use Jupiter notebook