Skip to content

Instantly share code, notes, and snippets.

@paulhankin
Created April 11, 2020 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulhankin/76881539644a976993069e6671c10e16 to your computer and use it in GitHub Desktop.
Save paulhankin/76881539644a976993069e6671c10e16 to your computer and use it in GitHub Desktop.
def g0(sx, sy, px, py, cache):
if sx < min(px, py) or sy < min(px, py):
return 0
if sx*sy < px*py:
return 0
if sx*sy == px*py:
return 1 if (sx==px and sy==py) or (sx==py and sy==px) else 0
best = 0
for i in range(1, sx):
best = max(best, guillotine(i, sy, px, py, cache) + guillotine(sx-i, sy, px, py, cache))
for i in range(1, sy):
best = max(best, guillotine(sx, i, px, py, cache) + guillotine(sx, sy-i, px, py, cache))
return best
def guillotine(sx, sy, px, py, cache):
if (sx, sy) not in cache:
cache[sx, sy] = g0(sx, sy, px, py, cache)
return cache[sx, sy]
print(guillotine(300//5, 200//5, 55//5, 40//5, dict()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment