当前位置:网站首页>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];
}
};
边栏推荐
- Promise details
- mybaits-puls 在xml文件中写sql语句 会报错 Invalid bound statement (not found):
- 微信小程序开发(原生和uniapp)DOM标签对比介绍
- 网狐游戏服务器房间配置约战定制功能实现
- AtomicInteger原子操作类
- The meaning and research significance of mathematical methodology
- Method to determine whether it is an array
- VTK vtkplane and vtkcutter use
- Stack -- one of two common linear structures of linear structure
- WPF 数据绑定(四)
猜你喜欢

Leetcode-141. Linked List Cycle

Difference between byte and bit
![[probability theory and mathematical statistics] Dr. monkey's notes p41-44 statistics related topics, determination of three distributions, properties, statistics subject to normal distribution in gen](/img/93/d1014b07c924195e062dc83d69b14a.png)
[probability theory and mathematical statistics] Dr. monkey's notes p41-44 statistics related topics, determination of three distributions, properties, statistics subject to normal distribution in gen

模块化笔记

Duality-Gated Mutual Condition Network for RGBT Tracking

Common troubleshooting tools and analysis artifacts are worth collecting

VTK vtkplane and vtkcutter use

Luogu p1091 chorus formation (longest ascending subsequence)

核查医药代表备案信息是否正确

无心剑汉英双语诗001.《爱》
随机推荐
Henan college entrance examination vs Tianjin college entrance examination (2008-2021)
Reconstruction and preheating of linked list information management system (2) how to write the basic logic using linear discontinuous structure?
网狐游戏服务器房间配置约战定制功能实现
Flat design, blog website (VIII) code source code
ESP32学习笔记(49)——ESP-WIFI-MESH接口使用
微信小程序开发(原生和uniapp)DOM标签对比介绍
Unity 全景漫游过程中使用AWSD控制镜头移动,EQ控制镜头升降,鼠标右键控制镜头旋转。
常用问题排查工具和分析神器,值得收藏
[MATLAB image fusion] particle swarm optimization adaptive multispectral image fusion [including source code phase 004]
The meaning and research significance of mathematical methodology
Comparison of DOM tags of wechat applet development (native and uniapp)
Difference between byte and bit
Graph Attention Tracking
【LeetCode】-- 17.电话号码的字母组合
saltstack的常用模块
VTK-vtkPlane和vtkCutter使用
Flutter Container组件
mybaits-puls 在xml文件中写sql语句 会报错 Invalid bound statement (not found):
Zabbix 监控主机是否在线
Heartless sword Chinese English bilingual poem 001 Love