当前位置:网站首页>[leetcode sword finger offer 10 - II. Frog jumping steps (simple)]
[leetcode sword finger offer 10 - II. Frog jumping steps (simple)]
2022-04-23 21:21:00 【Minaldo7】
subject :
A frog can jump up at a time 1 Stepped steps , You can jump on it 2 Stepped steps . Ask the frog to jump on one n How many jumps are there in the steps .
The answer needs to be modelled 1e9+7(1000000007), If the initial result of calculation is :1000000008, Please return 1.
Example 1:
Input :n = 2
Output :2
Example 2:
Input :n = 7
Output :21
Example 3:
Input :n = 0
Output :1
Tips :
0 <= n <= 100
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/qing-wa-tiao-tai-jie-wen-ti-lcof
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
The problem solving process :
class Solution {
public int numWays(int n) {
// if(n == 0 || n == 1) return 1;
// int front = 1, back = 1, fibn =0;
// for(int i = 2;i<=n;i++){
// fibn = front + back;
// if(fibn >= 1000000007)
// fibn -= 1000000007;
// front = back;
// back = fibn;
// }
// return fibn;
if(n <= 1) return 1;
int dp[] = new int[n+1];
dp[0] = 1;
dp[1] = 1;
//dp[2] = 2;
for(int i = 2; i < n+1; i++){
dp[i] = (dp[i-1] + dp[i-2])%1000000007;
}
return dp[n];
}
}
Execution results :

notes : Multiplication of large numbers , Why should we take modules for the permutation and combination of large numbers ?
because :1000000007 It's a prime number ( prime number ), The remainder of prime numbers can avoid the conflict of results to the greatest extent / repeat
版权声明
本文为[Minaldo7]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/111/202204210544479549.html
边栏推荐
- Introduce structured concurrency and release swift 5.5!
- The more you use the computer, the slower it will be? Recovery method of file accidental deletion
- Some thoughts on super in pytorch, combined with code
- Crisis is opportunity. Why will the efficiency of telecommuting improve?
- Factory mode
- [SDU chart team - core] enumeration of SVG attribute class design
- go defer
- Send email to laravel
- [leetcode refers to offer 27. Image of binary tree (simple)]
- Google tries to use rust in Chrome
猜你喜欢

Centos7 builds MySQL master-slave replication from scratch (avoid stepping on the pit)

Prim、Kruskal

Two Stage Detection

小米手机全球已舍弃“MI”品牌,全面改用“xiaomi”全称品牌

Problem brushing plan -- dynamic programming (IV)
![[leetcode refers to the substructure of offer 26. Tree (medium)]](/img/53/b34ed5f46706f80bc1a9fcdb1481ae.png)
[leetcode refers to the substructure of offer 26. Tree (medium)]

MySQL数据库常识之储存引擎

Write table of MySQL Foundation (create table)

Yolov5 NMS source code understanding

ROS学习笔记-----ROS的使用教程
随机推荐
UKFslam
Automatic heap dump using MBean
How to make Jenkins job run automatically after startup
41. 缺失的第一个正数
Tensorflow realizes gradient accumulation, and then returns
Graph traversal - BFS, DFS
Mysql database common sense storage engine
Question brushing plan -- backtracking method (I)
【SDU Chart Team - Core】SVG属性类设计之枚举
go reflect
Norm normalization in tensorflow and pytorch of records
Tensorflow1. X and 2 How does x read those parameters saved in CKPT
Gsi-ecm digital platform for engineering construction management
MySQL basic collection
Reference of custom message in ROS function pack failed
Unit function expansion
Arm architecture assembly instructions, registers and some problems
presto on spark 支持3.1.3记录
笔记本电脑卡顿怎么办?教你一键重装系统让电脑“复活”
What about laptop Caton? Teach you to reinstall the system with one click to "revive" the computer