当前位置:网站首页>Sword finger offer II 091 Paint the house
Sword finger offer II 091 Paint the house
2022-06-25 15:36:00 【anieoo】
Original link : The finger of the sword Offer II 091. Paint the house

solution:
Simple dp
class Solution {
public:
int minCost(vector<vector<int>>& costs) {
int n = costs.size();
vector<vector<int>> dp(n + 1, vector<int> (3));
//dp[i][j] It means to put in front of i House dyeing , The first i A house is dyed j Minimum cost of color
//0: Red 1: Blue 2: green
dp[1][0] = costs[0][0];
dp[1][1] = costs[0][1];
dp[1][2] = costs[0][2];
for(int i = 2;i <= n;i++) {
dp[i][0] = min(dp[i - 1][1], dp[i - 1][2]) + costs[i - 1][0];
dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]) + costs[i - 1][1];
dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]) + costs[i - 1][2];
}
return min(min(dp[n][0], dp[n][1]), dp[n][2]);
}
};边栏推荐
- The situation and suggestions of a software engineering associate graduate who failed in the postgraduate entrance examination
- Paddlepaddle paper reproduction course biggan learning experience
- JMeter reading and writing excel requires jxl jar
- Efficient pytorch: how to eliminate training bottlenecks
- Using reentrantlock and synchronized to implement blocking queue
- [paper notes] rethinking and improving relative position encoding for vision transformer
- Agent and classloader
- Software packaging and deployment
- Joseph Ring - formula method (recursive formula)
- Markdown learning
猜你喜欢

Principle and implementation of MySQL master-slave replication (docker Implementation)

google_ Breakpad crash detection

MySQL performance optimization - index optimization

Postman usage notes, interface framework notes

Distributed token

QT set process startup and self startup

Stack and queue

QT pattern prompt box implementation

Could not connect to redis at 127.0.0.1:6379 in Windows

Custom structure type
随机推荐
Several common optimization methods
解决Visio和office365安装兼容问题
Summary of four parameter adjustment methods for machine learning
Core mode and immediate rendering mode of OpenGL
(1) Introduction
How to download and install Weka package
Data preprocessing - normalization and standardization
Data feature analysis skills - correlation test
Is it safe to open a stock account through the account opening link given by the account manager? I want to open an account
程序员 VS 黑客的思维 | 每日趣闻
QT source code online view
Is it safe to open a stock account in Guoxin golden sun?
The difference between sizeof and strlen
Record the time to read the file (the system cannot find the specified path)
[paper notes] contextual transformer networks for visual recognition
Statistical analysis - data level description of descriptive statistics
About?: Notes for
QT excel table read / write library - qtxlsx
Go language modifies / removes multiple line breaks in strings
55 specific ways to improve program design (2)