示例1:
示例2:
class Solution {public int waysToStep(int n) {if(n == 1){return 1;
}
if(n == 2){return 2;
}
if(n == 3){return 4;
}
int[] dp = new int[n + 1];
dp[1] = 1;
dp[2] = 2;
dp[3] = 4;
for(int i = 4;i<=n;i++){dp[i] = ((dp[i - 1] + dp[i - 2]) % 1000000007 + dp[i - 3]) % 1000000007;
}
return dp[n];
}
}
int waysToStep(int n)
{if(n == 1)
{return 1;
}
if(n == 2)
{return 2;
}
if(n == 3)
{return 4;
}
int* dp = (int*)malloc(sizeof(int) * (n + 1));
dp[1] = 1;
dp[2] = 2;
dp[3] = 4;
for(int i = 4;i<=n;i++)
{dp[i] = ((dp[i - 1] + dp[i - 2]) % 1000000007 + dp[i - 3]) % 1000000007;
}
return dp[n];
}
class Solution:
def waysToStep(self, n: int) ->int:
if n == 1:
return 1
if n == 2:
return 2
if n == 3:
return 4
dp = [0] * (n + 1)
dp[1] = 1
dp[2] = 2
dp[3] = 4
for i in range(4,n+1):
dp[i] = ((dp[i - 1] + dp[i - 2]) % 1000000007 + dp[i - 3]) % 1000000007
return dp[n]
十【提交结果】Java语言版
C语言版
Python语言版
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧