擅长:python、mysql、java
<p>只需检查所有组合。由于您只有5台设备,因此(最多)可以使用<code>6^5=7776</code>(因为这5个位置中的每一个都可能未使用,所以您必须使用<code>6</code>)。然后对每一种可能性,你都要检查它是否符合你的标准。我不明白为什么要花这么多时间。</p>
<p>下面的脚本在我的机器上不需要一秒钟就可以计算出这些东西。</p>
<pre><code>d1=[8,8,4,4,200]
d2=[16,0,16,0,250]
d3=[8,0,4,4,300]
d4=[16,8,4,4,300]
d5=[8,8,2,2,150]
dummy=[0,0,0,0,0]
t=[24,12,16,8]
import itertools
def computeit(devicelist, target):
def check(d, t):
for i in range(len(t)):
if sum([dd[i] for dd in d]) < t[i]:
return False
return True
results=[]
for p in itertools.combinations_with_replacement(devicelist, 5):
if check(p, t):
results.append(p)
return results
print(computeit([d1,d2,d3,d4,d5,dummy],t))
</code></pre>
<p>需要Python2.7。</p>