本文整理汇总了Python中bintrees.FastRBTree.max_key方法的典型用法代码示例。如果您正苦于以下问题:Python FastRBTree.max_key方法的具体用法?Python FastRBTree.max_key怎么用?Python FastRBTree.max_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bintrees.FastRBTree
的用法示例。
在下文中一共展示了FastRBTree.max_key方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: int
# 需要导入模块: from bintrees import FastRBTree [as 别名]
# 或者: from bintrees.FastRBTree import max_key [as 别名]
cur[ 0 ] = 0
i = 0
for elem in newInput:
v = elem[ 2 ]
w = elem[ 1 ]
#for line in fin:
#info = line.split()
#v = int( info[ 0 ] )
#w = int( info[ 1 ] )
#print newItems - i, (v,w), len( prev )#, len( testSet )
i += 1
for stepWeight in prev:
step = [ stepWeight, prev[ stepWeight ] ]
curv = cur.floor_item( step[ 0 ] )[ 1 ]
maxv = max( step[ 1 ], curv )
# compare prev and cur on same weight
if maxv == step[ 1 ]:
cur[ step[ 0 ] ] = maxv
nextw = step[ 0 ] + w
# using step weight as base, compare value of
# prev val( step weight ) + item val --> with current item
# and prev val( step weight + item weight ) --> without current item
if nextw < size and prev.floor_item( nextw )[ 1 ] < step[ 1 ] + v:
cur[ nextw ] = step[ 1 ] + v
prev = cur
cur = FastRBTree()
cur[ 0 ] = 0
print prev[ prev.max_key() ]