Skip to content

Instantly share code, notes, and snippets.

@majiang
Created May 12, 2012 13:03
Show Gist options
  • Save majiang/2666416 to your computer and use it in GitHub Desktop.
Save majiang/2666416 to your computer and use it in GitHub Desktop.
assignment method
def BF3(cost):
ret = 27
a = range(3)
for a[0] in range(3):
for a[1] in range(3):
for a[2] in range(3):
if sorted(a) == range(3):
ret = min(ret, sum(cost[i][j] for (i, j) in zip(range(3), a)))
return ret
def BF5(cost):
ret = 45
a = range(5)
for a[0] in range(5):
for a[1] in range(5):
for a[2] in range(5):
for a[3] in range(5):
for a[4] in range(5):
if sorted(a) == range(5):
ret = min(ret, sum(cost[i][j] for (i, j) in zip(range(5), a)))
return ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment