当前位置:网站首页>Niuke.com: minimum cost of climbing stairs
Niuke.com: minimum cost of climbing stairs
2022-06-30 16:39:00 【lsgoose】


This obviously needs to be done with dynamic programming , First , Let's set up an array of dynamic programming dp[n+1], among n Is the number of stairs ,dp[i] It means to arrive at the third i The minimum cost of a step . Set up a cost[n] To store the cost of climbing a certain stair . The price of the first stair is cost[n-1], And so on .
Next, the dynamic transfer equations are listed , Obviously , We either crossed two levels before , Or only one level has been crossed . If you have crossed two levels .
dp[i]=min(dp[i-2]+cost[i-2],dp[i-1]+cost[i-1])
The code is as follows :
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
vector<int> cost(n);
for(int i=0;i<n;++i){
cin>>cost[i];
}
vector<int> dp(n+1);
for(int i=2;i<=n;++i){
dp[i]=min(dp[i-2]+cost[i-2], dp[i-1]+cost[i-1]);
}
cout<<dp[n]<<endl;
return 0;
}边栏推荐
- KDD 2022 | how far are we from the general pre training recommendation model? Universal sequence representation learning model unisrec for recommender system
- mysql8报错:ERROR 1410 (42000): You are not allowed to create a user with GRANT解决办法
- Open source STM32 USB-CAN project
- How to connect the Internet Reading Notes - Summary
- 如何得到股票开户的优惠活动?在线开户安全么?
- 赛芯电子冲刺科创板:拟募资6.2亿 实控人谭健为美国籍
- What are the reasons for the errors reported by the Flink SQL CDC synchronization sqlserver
- RTP 发送PS流零拷贝方案
- In depth analysis of the core code of the gadgetinspector
- 【Verilog基础】关于Clock信号的一些概念总结(clock setup/hold、clock tree、clock skew、clock latency、clock transition..)
猜你喜欢

Policy Center > Google Play‘s Target API Level Policy
![[bjdctf2020]the mystery of ip|[ciscn2019 southeast China division]web11|ssti injection](/img/c2/d6760826b81589781574aebff61f9a.png)
[bjdctf2020]the mystery of ip|[ciscn2019 southeast China division]web11|ssti injection

topic: Privacy, Deception and Device Abuse

The new tea drinks are "dead and alive", but the suppliers are "full of pots and bowls"?

'&lt;', hexadecimal value 0x3C, is an invalid 问题解决

How cloudxr promotes the future development of XR

中国传奇教授李泽湘,正在批量制造独角兽

Arcmap操作系列:80平面转经纬度84
MySQL开放远程连接权限的两种方法

After 15 years of working on 21 types of hardware, where is Google?
随机推荐
【Unity UGUI】ScrollRect 动态缩放格子大小,自动定位到中间的格子
GaussDB创新特性解读:Partial Result Cache,通过缓存中间结果对算子进行加速
超 Nice 的表格响应式布局小技巧
Policy Center > Deceptive Behavior
[time series database incluxdb] code example for configuring incluxdb+ data visualization and simple operation with C under Windows Environment
“低代码”在企业数字化转型中扮演着什么角色?
大学生研究生毕业找工作,该选择哪个方向?
What is XR extended reality and what are the XR cloud streaming platforms
[CVE-2019-0193] - Apache Solr DataImport 远程命令执行分析
15年做糊21款硬件,谷歌到底栽在哪儿?
牛客网:最小花费爬楼梯
边缘计算平台如何助力物联网发展
药品管理系统加数据库,一夜做完,加报告
[machine learning] K-means clustering analysis
KDD 2022 | how far are we from the general pre training recommendation model? Universal sequence representation learning model unisrec for recommender system
Tencent two sides: @bean and @component are used on the same class. What happens?
RT-Thread 堆區大小設置
Policy Center > Device and Network Abuse
7 月 2 日邀你来TD Hero 线上发布会
RT thread heap size setting