当前位置:网站首页>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;
}
}
边栏推荐
- Wonderful review | i/o extended 2022 activity dry goods sharing
- 注解简化配置与启动时加载
- LeetCode 75. 颜色分类
- [concurrent programming] atomic operation CAS
- Character pyramid
- On the difference and connection between find and select in TP5 framework
- MySQL index types B-tree and hash
- Debug debugging - Visual Studio 2022
- LeetCode 532. 数组中的 k-diff 数对
- Escape from heaven and forget what he suffered. In ancient times, it was called the punishment of escape from heaven. Article collection
猜你喜欢

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

22-06-28 西安 redis(02) 持久化机制、入门使用、事务控制、主从复制机制

TP5 multi condition sorting

On a un nom en commun, maître XX.

LeetCode 438. 找到字符串中所有字母异位词

Tree DP acwing 285 A dance without a boss

Log4j2 vulnerability recurrence and analysis

剑指 Offer II 029. 排序的循环链表

干货!零售业智能化管理会遇到哪些问题?看懂这篇文章就够了

AcWing 787. 归并排序(模板)
随机推荐
DOM 渲染系统(render mount patch)响应式系统
Log4j2 vulnerability recurrence and analysis
Sword finger offer II 029 Sorted circular linked list
Redux - learning notes
请求参数的发送和接收
Really explain the five data structures of redis
Markdown learning
Too many open files solution
LeetCode 871. 最低加油次数
状态压缩DP AcWing 91. 最短Hamilton路径
[concurrent programming] concurrent security
[concurrent programming] atomic operation CAS
22-06-28 西安 redis(02) 持久化机制、入门使用、事务控制、主从复制机制
Annotations simplify configuration and loading at startup
JS non Boolean operation - learning notes
22-05-26 Xi'an interview question (01) preparation
即时通讯IM,是时代进步的逆流?看看JNPF怎么说
LeetCode 1089. 复写零
C language file reading and writing
Deep parsing JVM memory model