当前位置:网站首页>剑指 Offer II 091. 粉刷房子
剑指 Offer II 091. 粉刷房子
2022-06-25 15:32:00 【anieoo】

solution:
简单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]表示把前i个房子染色,第i个房子染成j颜色的最小花费
//0:红色 1:蓝色 2:绿色
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]);
}
};边栏推荐
- Sampling method and descriptive statistical function in R language
- Std:: vector minutes
- Data feature analysis skills - correlation test
- Efficient pytorch: how to eliminate training bottlenecks
- Design and implementation of thread pool
- One question per day, a classic simulation question
- Daily question, magic square simulation
- A deformation problem of Hanoi Tower
- About%*s and%* s
- Kali SSH Remote Login
猜你喜欢

Graphic control and layout basis of R visualization

Arthas source code learning-1

Install Kali extension 1: (kali resolution problem)

Std:: vector minutes

Common dynamic memory errors

User defined data type - structure

Character encoding minutes

Day01: learning notes

5 connection modes of QT signal slot

Could not connect to redis at 127.0.0.1:6379 in Windows
随机推荐
Esp8266 building smart home system
Errno perrno and strerrno
Judging the number of leap years from 1 to N years
JS select all exercise
Several common optimization methods
Core mode and immediate rendering mode of OpenGL
2. operator and expression multiple choice questions
Learning to Measure Changes: Fully Convolutional Siamese Metric Networks for Scene Change Detection
Cross compilation correlation of curl Library
Stderr and stdout related standard outputs and other C system APIs
Several solutions to the distributed lock problem in partial Internet companies
Data preprocessing - normalization and standardization
Character encoding minutes
股票开户用什么app最安全?知道的给说一下吧
A deformation problem of Hanoi Tower
Using Visual Studio
Completabilefuture of asynchronous tools for concurrent programming
Install Kali extension 1: (kali resolution problem)
客户经理给的开户链接办理股票开户安全吗?我想开个户
‘make_ unique’ is not a member of ‘std’