当前位置:网站首页>Leetcode DP three step problem
Leetcode DP three step problem
2022-07-02 23:33:00 【qq5924db5b70f63】
package dp.waysToStep;
/**
* Interview questions 08.01. Three step problem
* Three step problem . There is a child going up the stairs , The stairs have n Steps , Children can go to 1 rank 、2 Step or 3 rank . Implement a way , Calculate how many ways a child can go up stairs . The results could be big , You need to model the results 1000000007.
* <p>
* Example 1:
* <p>
* Input :n = 3
* Output :4
* explain : There are four ways to walk
* Example 2:
* <p>
* Input :n = 5
* Output :13
* Tips :
* <p>
* n The scope is [1, 1000000] Between
*/
public class waysToStep {
public static int waysToStep(int n) {
int size = n<3?3:n;
int[] dp = new int[size];
dp[0] = 1;
dp[1] = 2;
dp[2] = 4;
for (int i = 3; i < n; i++) {
//dp[i-3] The mold has been taken in the last step , The remaining two to prevent overflow also need to take the mold
dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007 + dp[i - 3];
dp[i] %= 1000000007;
}
return dp[n-1];
}
public static void main(String[] args) {
System.out.println(waysToStep(1));
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
Can't , I can learn ; backward , I can catch up ; Fall down , I can stand up !
边栏推荐
- Go basic constant definition and use
- How difficult is it to be high? AI rolls into the mathematics circle, and the accuracy rate of advanced mathematics examination is 81%!
- Integration of revolution and batch normalization
- Master the development of facial expression recognition based on deep learning (based on paddlepaddle)
- How to maintain the brand influence of clothing enterprises
- Temperature measurement and display of 51 single chip microcomputer [simulation]
- Third party payment function test point [Hangzhou multi tester _ Wang Sir] [Hangzhou multi tester]
- Doorplate making C language
- 面试过了,起薪16k
- Cryptographic technology -- key and ssl/tls
猜你喜欢

Li Kou brush questions (2022-6-28)

Redis expiration policy +conf record

JDBC練習案例

Connexion à distance de la tarte aux framboises en mode visionneur VNC
![[analysis of STL source code] imitation function (to be supplemented)](/img/40/a02a04a24f385a31e0484d1071ecec.jpg)
[analysis of STL source code] imitation function (to be supplemented)

Explain promise usage in detail

数据集-故障诊断:西储大学轴承的各项数据以及数据说明

Deep analysis of data storage in memory - C language

Catalogue of digital image processing experiments

【直播预约】数据库OBCP认证全面升级公开课
随机推荐
[array] binary search
Win11如何开启目视控制?Win11开启目视控制的方法
Prometheus deployment
基于Pyqt5工具栏按钮可实现界面切换-1
Dishes launcher small green program and directory management (efficiency tool)
YOLOX加强特征提取网络Panet分析
一文掌握基于深度学习的人脸表情识别开发(基于PaddlePaddle)
Speech recognition Series 1: speech recognition overview
Writing of head and bottom components of non routing components
Boost库链接错误解决方案
Interface switching based on pyqt5 toolbar button -1
Getting started with golang: for Range an alternative method of modifying the values of elements in slices
PHP get real IP
The concepts of terminal voltage, phase voltage and line voltage in FOC vector control and BLDC control are still unclear
【ML】李宏毅三:梯度下降&分类(高斯分布)
20220524_ Database process_ Statement retention
Win11启用粘滞键关闭不了怎么办?粘滞键取消了但不管用怎么解决
Pandora IOT development board learning (HAL Library) - Experiment 3 key input experiment (learning notes)
I've been interviewed. The starting salary is 16K
LINQ usage collection in C #