摘要:
问题: 假设有几种硬币,如1、3、5,并且数量无限。请找出能够组成某个数目的找零所使用最少的硬币数。 方法:dp, dp[i]: 面值为i的硬币所需要的硬币最少个数,dp[i]= 1+min(dp[i-coins[0]], dp[i-coins[1]],...) def change_coins(c 阅读全文
posted @ 2021-05-25 22:16
今夜无风
阅读(220)
评论(0)
推荐(0)
摘要:
class Project(object): def __init__(self): self.node = {} self.end_char = '#' def insert(self, word): node = self.node for char in word: node = node.s 阅读全文
posted @ 2021-05-25 20:11
今夜无风
阅读(168)
评论(0)
推荐(0)
摘要:
问题: 一只青蛙一次可以跳上1级台阶,也可以跳上2级台阶。求该青蛙跳上一个n级的台阶总共有多少种跳法? 方法:一维dp def go_stage(n): if not n: return if n==1 or n==2: return n if n==0: return 1 dp = [0] * ( 阅读全文
posted @ 2021-05-25 20:10
今夜无风
阅读(114)
评论(0)
推荐(0)