当前位置:网站首页>1269. number of options left in place
1269. number of options left in place
2022-06-11 07:01:00 【Not coriander】
There is a length of arrLen Array of , Start with a pointer in the index 0 It's about .
In every step of the operation , You can move the pointer to the left or right 1 Step , Or stay where you are ( The pointer cannot be moved out of the range of the array ).
Here are two integers steps and arrLen , Please calculate and return : Just in time to execute steps After the first operation , The pointer still points to the index 0 The number of schemes at .
Because the answer could be big , Please return the number of schemes model 10^9 + 7 After the results of the .
Example 1:
Input :steps = 3, arrLen = 2
Output :4
explain :3 Step after , All in all 4 There are two different ways to stop at the index 0 It's about .
towards the right , towards the left , Immobility
Immobility , towards the right , towards the left
towards the right , Immobility , towards the left
Immobility , Immobility , Immobility
Example 2:
Input :steps = 2, arrLen = 4
Output :2
explain :2 Step after , All in all 2 There are two different ways to stop at the index 0 It's about .
towards the right , towards the left
Immobility , Immobility
Example 3:
Input :steps = 4, arrLen = 2
Output :8
Tips :
1 <= steps <= 500
1 <= arrLen <= 10^6
class Solution {
public:
int numWays(int steps, int arrLen) {
int mod=1000000007;
int len=min(arrLen,steps+1);
//vector<vector<int>>dp(steps+1,vector<int>(len));
// int dp[steps+1][arrLen+2];
vector<int>dp(len);
vector<int>dp2(len);
dp[0]=1;
for(int i=1;i<=steps;i++){
for(int j=0;j<len;j++){
dp2[j]=dp[j];
if(j>0)dp2[j]=(dp2[j]+dp[j-1])%mod;
if(j<len-1)dp2[j]=(dp2[j]+dp[j+1])%mod;
}
dp=dp2;
//cout<<endl;
}
return dp[0];
}
};
边栏推荐
- Do you know what the quotation for it talent assignment service is? It is recommended that programmers also understand
- The difference between arrow function and ordinary function
- Nodejs database (Part 2)
- saltstack部署lnmp
- JVM from getting started to abandoning 1: memory model
- [matlab printed character recognition] OCR printed letter + number recognition [including source code 1861]
- 双周投融报:资本抢滩元宇宙游戏
- 数学方法论的含义和研究意义
- AtomicInteger原子操作类
- 核查医药代表备案信息是否正确
猜你喜欢

Shuttle container component
![[Xunwei dry goods] opencv test of Godson 2k1000 development board](/img/94/312bb1f0d5e8d49506f659ad23cd3a.jpg)
[Xunwei dry goods] opencv test of Godson 2k1000 development board

生物序列智能分析平台blog(1)

ESP32学习笔记(49)——ESP-WIFI-MESH接口使用

WPF 数据绑定(四)

Duality-Gated Mutual Condition Network for RGBT Tracking
![[deploy private warehouse based on harbor] 3 deploy harbor](/img/cd/be68a430e86b4b23ad93b42a338f00.jpg)
[deploy private warehouse based on harbor] 3 deploy harbor

Starting from scratch (IV) enemy aircraft flying out of the border disappear automatically

The difference between arrow function and ordinary function

【Matlab WSN通信】A_Star改进LEACH多跳传输协议【含源码 487期】
随机推荐
关于组织开展2022年宁波市重点首版次软件申报工作的通知
Library management system 2- demand analysis
JVM from getting started to giving up 2: garbage collection
【Matlab WSN通信】A_Star改进LEACH多跳传输协议【含源码 487期】
争议很大的问题
Summary of string processing skills III
Grayscale publishing through ingress
Leetcode hot topic 100 topic 11-15 solution
Cross-Modal Pattern-Propagation for RGB-T Tracking
洛谷P1091合唱队形(最长上升子序列)
核查医药代表备案信息是否正确
Use of qscriptengine class
[matlab printed character recognition] OCR printed letter + number recognition [including source code 1861]
A promise with bare hands
Notice on organizing the application for the first edition of Ningbo key software in 2022
Explain the difference between void 0 and undefined
mybaits-puls 在xml文件中写sql语句 会报错 Invalid bound statement (not found):
Illustrate the principle of one-way linked list and the method of JS to realize linked list [with source code]
Web API、DOM
你知道IT人才外派服务报价是怎样的么?建议程序员也了解下