当前位置:网站首页>力扣------使用最小花费爬楼梯
力扣------使用最小花费爬楼梯
2022-08-11 00:05:00 【qq_37760746】
int minCostClimbingStairs(int* cost, int costSize){
if(costSize==2){
return cost[0]>cost[1]?cost[1]:cost[0];
}
int dp[costSize+1][2];
dp[0][0]=cost[0];
dp[1][0]=cost[1]+cost[0];
for(int a=2;a<costSize+1;a++){
if(a==costSize){
dp[a][0]=dp[a-2][0]<dp[a-1][0]?dp[a-2][0]:dp[a-1][0];
}
else{
dp[a][0]=cost[a]+(dp[a-2][0]<dp[a-1][0]?dp[a-2][0]:dp[a-1][0]);
}
}
dp[1][1]=cost[1];
dp[2][1]=cost[2]+cost[1];
for(int a=3;a<costSize+1;a++){
if(a==costSize){
dp[a][1]=dp[a-2][1]<dp[a-1][1]?dp[a-2][1]:dp[a-1][1];
}
else{
dp[a][1]=cost[a]+(dp[a-2][1]<dp[a-1][1]?dp[a-2][1]:dp[a-1][1]);
}
}
return dp[costSize][0]<dp[costSize][1]?dp[costSize][0]:dp[costSize][1];
}
边栏推荐
- 报错:Client does not support authentication protocol requested by server; consider upgrading MySQL cli
- UOJ#749-[UNR #6]稳健型选手【贪心,分治,主席树】
- Navicat 16-数据库工具
- Go项目配置管理神器之viper使用详解
- 2. Dependency management and automatic configuration
- [C Language Chapter] Detailed explanation of bitwise operators (“<<”, “>>”, “&”, “|”, “^”, “~”)
- Dump文件生成,内容,以及分析
- SQL注入基础---order by \ limit \ 宽字节注入
- 11. Custom Converter
- 【openpyxl】只读模式、只写模式
猜你喜欢
13. Content Negotiation
[Excel知识技能] 将“假“日期转为“真“日期格式
2. Dependency management and automatic configuration
英文文献阅读时,如何做笔记?
Design and Realization of Employment Management System in Colleges and Universities
YOLOv5的Tricks | 【Trick12】YOLOv5使用的数据增强方法汇总
[C] the C language program design, dynamic address book (order)
YOLOv5的Tricks | 【Trick13】YOLOv5的detect.py脚本的解析与简化
How to easily obtain the citation format of references?
Multilingual Translation - Multilingual Translation Software Free
随机推荐
SQL injection base
【pypdf2】安装、读取和保存、访问页面、获取文本、读写元数据、加密解密
分库分表ShardingSphere-JDBC笔记整理
2022下半年软考「高项」易混淆知识点汇总(2)
详谈二叉搜索树
8. WEB 开发-静态资源访问
Call activity of Activiti7 sub-process
复制带随机指针的链表——LeetCode
In 22 years, the salary of programmers nationwide in January was released, only to know that there are so many with annual salary of more than 400,000?
软件测试证书(1)—— 软件评测师
Go项目配置管理神器之viper使用详解
Which translation software is more accurate [Free]
Why do programming languages have the concept of variable types?
9. Rest style request processing
两个链表的第一个公共节点——LeetCode
服务器小常识
[Data Visualization] Chart Design Principles
CF1427F-Boring Card Game【贪心】
Where can I download IEEE papers?
“蔚来杯“2022牛客暑期多校训练营3 DF题解