我想问一道 LeetCode 变形题:(70)爬梯(变形)
原题: 假设你正在爬梯。需要 n 阶你才能到达顶。
每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到顶呢?
注意:给定 n 是一个正整数。
变形: 假设你正在爬梯。需要 n 阶你才能到达顶。
每次你可以爬 1 或 2 或 3 个台阶,且每次上的台阶不相同。你有多少种不同的方法可以爬到顶呢?
注意:给定 n 是一个正整数。
哥哥们 这个变形 怎么解答 ? 怎么个思路 ?
原题: 假设你正在爬梯。需要 n 阶你才能到达顶。
每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到顶呢?
注意:给定 n 是一个正整数。
变形: 假设你正在爬梯。需要 n 阶你才能到达顶。
每次你可以爬 1 或 2 或 3 个台阶,且每次上的台阶不相同。你有多少种不同的方法可以爬到顶呢?
注意:给定 n 是一个正整数。
哥哥们 这个变形 怎么解答 ? 怎么个思路 ?
最后再走一波数值和是 n 的遍历?
基本上是 frog jump 的变体
那你到 n 的方法数 就是 走 2,3 到 n-1 的方法数 + 走 1,3 到 n -2 的方法数 + 走 1,2 到 n-3 的方法数
for i in range(m, n):
for j in range(m):
dp[i][j] = sum(dp[i – j – 1]) – dp[i – j – 1][j]
return sum(dp[n – 1])
“`
大概是这样吧
they are calculating the number (N) of ways of change a quatity (A) using K kinds of coins by adding:
1. the number of ways (X) of changing A without coins of the first type.
2.The number of ways (Y) of changing (A – D), where D is the denomination of the fisrt coin, using ALL K types of coins.
确定一下初始值,然后计算 result = s[n][1]+s[n][2]+s[n][3] 即可 ?
你百度一下一堆. 比在 v 站问高效啊.