Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n, m = map(int, input().split())
- d = [[1<<30 for j in range(m+1)] for i in range(n+1)]
- for i in range(1, min(n,m)+1):
- d[i][i] = 0 #!!patrat NU inseamna patratel!!!
- for i in range(n+1):
- for j in range(m+1):
- z = 1
- while z <= i-z:
- d[i][j] = min(d[i][j], 1+d[z][j]+d[i-z][j])
- z += 1
- z = 1
- while z <= j-z:
- d[i][j] = min(d[i][j], 1+d[i][z]+d[i][j-z])
- z += 1
- print(d[n][m])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement