fork(1) download
  1. from operator import itemgetter
  2. import collections
  3.  
  4. tmp = [(0, 30), (0, 20), (10, 40), (30, 50), (50, 90), (70, 100), ]
  5. aa = sorted(tmp, key=itemgetter(1)) # sort with respect to 1st elem
  6. a = set(aa)
  7. space = 100
  8. d_conn = 15
  9. RTT = d_conn*2
  10. bandwidth = 10
  11.  
  12. def get_marginal_cost(fragment):
  13. return RTT + (fragment[1] - fragment[0])/bandwidth
  14.  
  15. def dfs(a, start, path=None):
  16. if path is None:
  17. path = [start, ]
  18. if start[1] == space:
  19. yield path
  20. for frgmt in a - set(path):
  21. l = frgmt[0]
  22. r = frgmt[1]
  23. # if start[0] < l <= start[1] <= r:
  24. if l <= start[1] <= r:
  25. yield dfs(a, frgmt, path + [frgmt, ])
  26.  
  27. for output in list(dfs(a, (0, 0))):
  28. for outpu in list(output):
  29. for outp in list(outpu):
  30. for out in list(outp):
  31. for ou in list(out):
  32. for o in list(ou):
  33. print o
  34.  
Success #stdin #stdout 0.02s 8168KB
stdin
Standard input is empty
stdout
[(0, 0), (0, 20), (10, 40), (30, 50), (50, 90), (70, 100)]
<generator object dfs at 0xb76258ec>
[(0, 0), (0, 20), (0, 30), (30, 50), (50, 90), (70, 100)]
[(0, 0), (0, 30), (10, 40), (30, 50), (50, 90), (70, 100)]
(0, 0)
(0, 30)
(30, 50)
(50, 90)
(70, 100)