当前位置:网站首页>力扣------使用最小花费爬楼梯
力扣------使用最小花费爬楼梯
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];
}
边栏推荐
- ASIO4ALL是什么
- 地下管廊可视化管理系统搭建
- Web-based meal ordering system in epidemic quarantine area
- 图像识别和语义分割的区别
- Which translation software is more accurate [Free]
- [C language] Implementation of guessing number game
- Dump file generation, content, and analysis
- 【pypdf2】安装、读取和保存、访问页面、获取文本、读写元数据、加密解密
- 12. 处理 JSON
- 如何破坏Excel文件,让其显示文件已损坏方法
猜你喜欢

“蔚来杯“2022牛客暑期多校训练营3 DF题解

YOLOv5的Tricks | 【Trick13】YOLOv5的detect.py脚本的解析与简化

Qt入门(六)——抽奖系统的实现

web 性能提升(将持续更新……)

线上突然查询变慢怎么核查
![[Excel knowledge and skills] Convert text numbers to numeric format](/img/7e/16a068025ec2639b343436c7f5b245.png)
[Excel knowledge and skills] Convert text numbers to numeric format

15. 拦截器-HandlerInterceptor

How to easily obtain the citation format of references?

YOLOv5的Tricks | 【Trick12】YOLOv5使用的数据增强方法汇总

Dump file generation, content, and analysis
随机推荐
盘点美军的无人机家底
[Excel knowledge and skills] Convert numeric format numbers to text format
【爬虫】scrapy创建运行爬虫、解析页面(嵌套url)、自定义中间件(设置UserAgent和代理IP)、自定义管道(保存到mysql)
[C language] Implementation of guessing number game
App regression testing, what are the efficient testing methods?
UOJ#749-[UNR #6]稳健型选手【贪心,分治,主席树】
“蔚来杯“2022牛客暑期多校训练营4 ADHK题解
Timers, synchronous and asynchronous APIs, file system modules, file streams
Navicat 16-数据库工具
Mysql.慢Sql
Software protection scenario of NOR FLASH flash memory chip ID application
"NIO Cup" 2022 Nioke Summer Multi-School Training Camp 3 DF Problem Solving
11. 自定义转换器
只会懒汉式和饿汉式 你还不懂单例模式!
YOLOv5的Tricks | 【Trick10】从PyTorch Hub加载YOLOv5
There is no recycle bin for deleted files on the computer desktop, what should I do if the deleted files on the desktop cannot be found in the recycle bin?
Analysis of LENS CRA and SENSOR CRA Matching Problems
Jvm.分析工具(jconsole,jvisualvm,arthas,jprofiler,mat)
5. Lombok
[Data Visualization] Chart Design Principles