当前位置:网站首页>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;
}
}
边栏推荐
- Summary of methods for counting the number of file lines in shell scripts
- 第一个Servlet
- Concurrent programming (VI) ABA problems and solutions under CAS
- Life cycle of Servlet
- Mortgage Calculator
- Alibaba canal actual combat
- TP5 multi condition sorting
- LeetCode 438. 找到字符串中所有字母异位词
- Sending and receiving of request parameters
- 树形DP AcWing 285. 没有上司的舞会
猜你喜欢
LeetCode 75. 颜色分类
Allocation exception Servlet
LeetCode 438. 找到字符串中所有字母异位词
LeetCode 30. 串联所有单词的子串
I made mistakes that junior programmers all over the world would make, and I also made mistakes that I shouldn't have made
Monotonic stack -84 The largest rectangle in the histogram
excel一小时不如JNPF表单3分钟,这样做报表,领导都得点赞!
LeetCode 513. 找树左下角的值
PHP uses foreach to get a value in a two-dimensional associative array (with instances)
Parameters of convolutional neural network
随机推荐
DOM 渲染系统(render mount patch)响应式系统
Annotations simplify configuration and loading at startup
即时通讯IM,是时代进步的逆流?看看JNPF怎么说
What is the difference between sudo apt install and sudo apt -get install?
精彩回顾|I/O Extended 2022 活动干货分享
常见渗透测试靶场
数字化管理中台+低代码,JNPF开启企业数字化转型的新引擎
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
Education informatization has stepped into 2.0. How can jnpf help teachers reduce their burden and improve efficiency?
浅谈企业信息化建设
[concurrent programming] concurrent security
Deep parsing (picture and text) JVM garbage collector (II)
Binary tree traversal (first order traversal. Output results according to first order, middle order, and last order)
Apache startup failed phpstudy Apache startup failed
状态压缩DP AcWing 291. 蒙德里安的梦想
Character pyramid
22-06-28 西安 redis(02) 持久化机制、入门使用、事务控制、主从复制机制
C language student management system based on linked list, super detailed
Mortgage Calculator