当前位置:网站首页>Sword finger offer special breakthrough version 91. Painting the house
Sword finger offer special breakthrough version 91. Painting the house
2022-04-22 03:04:00 【Catch Lulu, little cute (๑ • • ๑)】
Ideas
- set up dp[i][j] It's No i Paint the first house j The total cost of each color , So naturally dp[i][j] = min{dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]} + cost[i]
- in other words dp[i][j] The minimum value of the other two colors for the previous house should be added to the color of this house j Cost
class Solution {
public int minCost(int[][] costs) {
int[][] dp = new int[2][3];
System.arraycopy(costs[0], 0, dp[0], 0, 3);
for (int i = 1; i < costs.length; i++) {
for (int j = 0; j < 3; j++) {
dp[i % 2][j] = Math.min(dp[(i - 1) % 2][(j + 1) % 3], dp[(i - 1) % 2][(j + 2) % 3]) + costs[i][j];
}
}
int index = (costs.length - 1) % 2;
return Math.min(Math.min(dp[index][0], dp[index][1]), dp[index][2]);
}
}
版权声明
本文为[Catch Lulu, little cute (๑ • • ๑)]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220300400758.html
边栏推荐
- Share price plummeted Robinhood acquired British encryption company for expansion
- 内置函数123
- 【Laravel系列4.7】连接redis以及缓存应用
- Favorite tips link
- Built in functions 123
- Quick start NFT from technical principle, mainstream platform and market prospect
- Will you "sell" SQL?
- 824. 山羊拉丁文(字符串分割 + 字符串替代)
- 网络和多媒体知识(3)
- Day11 job
猜你喜欢

外包干了四年,废了

Evolution and construction of data warehouse architecture

Install and deploy phpstudy + DVWA vulnerability drill platform
![[NCTF2019]Fake XML cookbook](/img/55/b0f996fd1db2792c14444bcba39377.png)
[NCTF2019]Fake XML cookbook

Flutter04 widget initial experience

(Advanced) C function call

Flink 细粒度资源管理新特性解读

Kerberos authentication protocol

The sequence table implements the operation of the stack

Wechat jsapi payment method and error (the URL of the current page is not registered, and the payment verification signature fails)
随机推荐
Stackoverflow:IActionContextAccessor Is Null
Protocole d'authentification Kerberos
Friends don't see how to add, write it down first.
Create a two-way linked list (detailed explanation)
Delphi automatically adapts to the screen size
(Advanced) C function call
golang依赖注入wire使用 执行wire命令时报错:bash: wire: command not found
Verse protocol: a wonderful idea to optimize NFT liquidity
Golang dependency injection wire. When executing the wire command, an error is reported: bash: Wire: command not found
On the attention economy of NFT
How to run collabora office in openshift
Why is the country established
Wechat H5 payment (reporting cross domain issues)
Object class
The sequence table implements the operation of the stack
Redis事件驱动框架(上):何时使用select、poll、epoll?
MODEM拨号放音,原来写在大富翁,汇总过来。
Regression prediction | MATLAB realizes Bayes Gru (Bayes optimized gating cycle unit) multiple input and single output
Detailed explanation of basic properties of binary sort tree
Redis event driven framework (Part 1): when to use select, poll and epoll?