You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This discussion was converted from issue #70 on September 15, 2026 11:04.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Problem link
https://leetcode.com/problems/number-of-ways-of-cutting-a-pizza/
Problem Summary
사과가 올려져 있는 피자가 있을 때 사과가 1개 이상 올라가 있도록 피자를 k개로 나누는 경우의 수를 구하는 문제.
피자는 행 또는 열로 죽 자를 수 있다.
Solution
딱 보니 모듈러도 있고 자른 모양이 DP 할 수 있게 생겼다.
점화식을 간단히 만들면
여기까지는 간단한데 사과 개수가 최소 1개 이상 있어야 한다.
입력 크기가 작아서 무식하게 O(nm) 돌면서 사과 개수를 세어줘도 충분히 돌아간다.
2d prefix sum을 이용하면 사과 개수를 O(1)로 구할 수 있고 좀 빨라지긴 한다.
Source Code
O(n^2 m^2 k) - 2497 ms
O(nm (n+m) k) - 991 ms
All reactions