Advertisement
Guest User

CSES Rectangle Cutting TL

a guest
Jul 29th, 2020
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. n, m = map(int, input().split())
  2. d = [[1<<30 for j in range(m+1)] for i in range(n+1)]
  3. for i in range(1, min(n,m)+1):
  4.     d[i][i] = 0 #!!patrat NU inseamna patratel!!!
  5. for i in range(n+1):
  6.     for j in range(m+1):
  7.         z = 1
  8.         while z <= i-z:
  9.             d[i][j] = min(d[i][j], 1+d[z][j]+d[i-z][j])
  10.             z += 1
  11.         z = 1
  12.         while z <= j-z:
  13.             d[i][j] = min(d[i][j], 1+d[i][z]+d[i][j-z])
  14.             z += 1
  15. print(d[n][m])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement