【发布时间】:2015-03-30 17:14:13
【问题描述】:
给定杆的长度和前 3 根杆的 P(价格)。我们要填写剩下的鱼竿可能得到的价格。假设我们可以根据需要切割较长的部分。
L = 1 2 3 4 5 6 7 8
p = 3 8 12
我们基本上希望得到每个缺失长度价格的最高价格。
我的方法 我相信,由于我们获得了长度为 1,2 和 3 的杆的最优惠价格,因此我们可以为下一个杆生成所有可能的组合。
For example to get price of rod where L = 4
price of rod where L = 1 + rod where L = 3 = 15
price of rod where L = 2 + rode where L = 2 = 16
Therefore price of rod wehre L = 4 = 16 since 16 > 15.
For example to get price of rod where L = 5
price of rod where L = 1 + rod where L = 2 and rod where L = 2 = 19
price of rod where L = 3 + rod where L = 2 = 20
price of rod where L = 4 + rod where L = 1 = 19
所以这是我正在遵循的一种方法。但是我不确定我是否正确。如果有人可以验证这种方法并且也可以帮助我从中推导出一个公式,我也希望它。我不是在寻找代码,因为理解问题足以编写代码。
【问题讨论】:
标签: algorithm dynamic-programming