如何简化这个方程式

时间:2020-04-12 08:57:15

标签: math mathematical-optimization

问题:给定一个介于0和6之间的数字,该数字4、2、1的组合将等于给定的数字。一个数字只能使用一次(不能连续6次执行1次以获得给定的6)。

Examples:
Value = 6
4 = 1
2 = 1
1 = 0

Value = 4
4 = 1
2 = 0
1 = 0

Value = 3
4 = 0
2 = 1
1 = 1

Current forumlas, where given number is 6:
4 = Floor(6/4)
2 = Floor(6%4)/2
1 = Floor[(6%4)%2]/1

鉴于这是一种模式,我将如何简化我的公式? 这个模式有什么特别的名字吗?

1 个答案:

答案 0 :(得分:0)

您可以遵循贪婪的方法。开始从列表中减去列表中最大的元素(此处为4-2-1),该元素也小于您要分解的数字,然后重复直到达到0。

相关问题