原题题目
代码实现(首刷自解)
class Solution {
public:int numWays(int steps, int arrLen) {
vector<int> dp1(arrLen,0),dp2(arrLen,0),temp(dp1);dp1[0] = dp1[1] = 1;int mod = 1000000007,ret = 0;for(int i=2;i<=steps;++i){
dp2 = dp1;dp1 = temp;for(int j=0;j<=(i-1<=arrLen-1 ? i-1:arrLen-1);++j){
if(j>=1) dp1[j-1] = (dp1[j-1]+dp2[j])%mod;dp1[j] = (dp1[j]+dp2[j])%mod;if(j+1<=arrLen-1) dp1[j+1] = (dp1[j+1]+dp2[j])%mod;}}return dp1[0];}
};