当前位置:网站首页>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 !
边栏推荐
- 提交代码流程
- Troubleshooting the cause of the crash when STM32 serial port dam receives 253 bytes
- PHP get real IP
- The difference between new and make in golang
- 高数有多难?AI 卷到数学圈,高数考试正确率 81%!
- [proteus simulation] 51 MCU +lcd12864 push box game
- golang中new与make的区别
- Where is the win11 microphone test? Win11 method of testing microphone
- “一个优秀程序员可抵五个普通程序员!”
- Detailed explanation of 'viewpager' in compose | developer said · dtalk
猜你喜欢
Golang common settings - modify background
Load balancing cluster (LBC)
JSON data transfer parameters
为什么RTOS系统要使用MPU?
YOLOX加强特征提取网络Panet分析
Eight bit responder [51 single chip microcomputer]
Hisilicon VI access video process
ADC of stm32
Getting started with golang: for Range an alternative method of modifying the values of elements in slices
RuntimeError: no valid convolution algorithms available in CuDNN
随机推荐
Fudian bank completes the digital upgrade | oceanbase database helps to layout the distributed architecture of the middle office
第三方支付功能测试点【杭州多测师_王sir】【杭州多测师】
VIM interval deletion note
Connexion à distance de la tarte aux framboises en mode visionneur VNC
[error record] the flutter reports an error (could not resolve io.flutter:flutter_embedding_debug:1.0.0.)
高数有多难?AI 卷到数学圈,高数考试正确率 81%!
Dishes launcher small green program and directory management (efficiency tool)
How to maintain the brand influence of clothing enterprises
跨境电商如何通过打好数据底座,实现低成本稳步增长
Master the development of facial expression recognition based on deep learning (based on paddlepaddle)
Use of recyclerview with viewbinding
Li Kou brush questions (2022-6-28)
Troubleshooting the cause of the crash when STM32 serial port dam receives 253 bytes
潘多拉 IOT 开发板学习(HAL 库)—— 实验4 串口通讯实验(学习笔记)
YOLOX加强特征提取网络Panet分析
BBR encounters cubic
Print out mode of go
Ideal car × Oceanbase: when the new forces of car building meet the new forces of database
Go basic anonymous variable
"A good programmer is worth five ordinary programmers!"