当前位置:网站首页>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 !
边栏推荐
- 内网渗透 | 手把手教你如何进行内网渗透
- 简述中台的常识
- Fudian bank completes the digital upgrade | oceanbase database helps to layout the distributed architecture of the middle office
- Load balancing cluster (LBC)
- Bean load control
- Highly available cluster (HAC)
- PHP get real IP
- Arduino - 字符判断函数
- Go basic constant definition and use
- [array] binary search
猜你喜欢

Catalogue of digital image processing experiments

基于FPGA的VGA协议实现

【STL源码剖析】仿函数(待补充)

Interface switching based on pyqt5 toolbar button -1

JDBC练习案例

Hisilicon VI access video process
![[error record] the flutter reports an error (could not resolve io.flutter:flutter_embedding_debug:1.0.0.)](/img/93/dc940caebe176177e4323317ebf4fa.jpg)
[error record] the flutter reports an error (could not resolve io.flutter:flutter_embedding_debug:1.0.0.)

Cryptography -- the mode of block cipher

Where is the win11 microphone test? Win11 method of testing microphone

MarkDown基本语法
随机推荐
The difference between new and make in golang
What experience is there only one test in the company? Listen to what they say
C# MVC创建一个视图摆脱布局的影响
@How to use bindsinstance in dagger2
Li Kou brush questions (2022-6-28)
数字图像处理实验目录
The concepts of terminal voltage, phase voltage and line voltage in FOC vector control and BLDC control are still unclear
Markdown basic grammar
All things work together, and I will review oceanbase's practice in government and enterprise industry
Request and response
Why does RTOS system use MPU?
Prometheus deployment
Cryptographic technology -- key and ssl/tls
C MVC creates a view to get rid of the influence of layout
【STL源码剖析】仿函数(待补充)
Wechat applet basic learning (wxss)
Hisilicon VI access video process
Where is the win11 microphone test? Win11 method of testing microphone
2022 latest and complete interview questions for software testing
PHP get real IP