当前位置:网站首页>Sword finger offer 71: step jumping expansion problem
Sword finger offer 71: step jumping expansion problem
2022-07-20 21:27:00 【Swarford】
link
subject :
Ideas : Dynamic programming
Converse thinking , stay n Go down the steps , share 1+2+…n Methods ;
therefore f(n) = f(n−1)+f(n−2)+…+f(n−(n−1))+f(n−n) => f(0)+f(1)+f(2)+…+f(n−1)
because f(n−1)=f(n−2)+f(n−3)+…+f((n−1)−(n−2))+f((n−1)−(n−1));
After sorting it out f(n) = f(n−1)+f(n−1) = 2∗f(n−1) , Therefore, the number of schemes for each step is... Of the number of schemes for the previous step 2 times .
import java.util.*;
public class Solution {
int[] memo;
public int jumpFloorII(int n) {
memo=new int[n+1];
Arrays.fill(memo,-1);
return dp(n);
}
//
int dp(int n){
//base case
if(n<=2){
return n;
}
// Overlapping subproblems
if(memo[n]!=-1){
return memo[n];
}
memo[n]=dp(n-1) * 2;
return memo[n];
}
}
边栏推荐
- MetInfo 函数public function getcity() 错误:xxx function no permission load!!!
- To do difficult work
- Redis high availability: do you call this the principle of master-slave architecture data synchronization?
- 金仓数据库 KingbaseES SQL 语言参考手册 (3.8. 数据库对象、3.9. 数据库对象名称和限定符)
- 山西省第二届网络安全技能大赛(企业组)部分赛题WP(六)
- 【每日一题】731. 我的日程安排表Ⅱ
- Gson简单使用
- SAP mm transaction code Migo mobile type 561 error after saving -document number was already assigned
- Data distribution optimization: how to deal with data skew?
- 金仓数据库 KingbaseES SQL 语言参考手册 (3.3. 类型转换表、3.4. 常量)
猜你喜欢
DNS principle and configuration
ThreadLocal夺命11连问
go 操作 Excel
[quick start tutorial 2] crazy shell · open source formation UAV - Introduction to hardware resources
网络工程案例:CII公司的综合网络设计
How can Web3 enterprises use tokens to motivate employees?
[development tutorial 3] open source Bluetooth heart rate waterproof sports Bracelet - development environment construction
Vmware解决无法识别USB的问题
Redis practice: skillfully use data types to achieve 100 million level data statistics
DBC2000有什么作用?DBC2000的安装与配置
随机推荐
服务器带宽和家用宽带的区别?
getdata table 表格数据 join mysql方法
How can Web3 enterprises use tokens to motivate employees?
To do difficult work
Redis high availability: do you call this the principle of master-slave architecture data synchronization?
DBC2000有什么作用?DBC2000的安装与配置
[development tutorial 3] open source Bluetooth heart rate waterproof sports Bracelet - development environment construction
Redis 高可用篇:你管这叫 Sentinel 哨兵集群原理
Redis high availability: you call this sentinel sentinel cluster principle
Dest0g3 520迎新赛-web-funny_upload
Ajout, suppression, modification et exception de cookies
LVGL 8.2 Tabview & Window
How to choose a 10000 person game server?
Blueprint class view method
【golang从入门到实践】石头剪刀布游戏
10000人游戏服务器怎么选?
Apipost签约中国电信!携手加速企业数字化变革
中芯国际2018年营收33.6亿美元,14nm技术于今年量产
LVGL 8.2 Tabview
How to implement recursive function in wechat game making tool