Problem Statement
Rectangle Cutting
Implementation
void solve()
{
ll n, m;
cin >> n >> m;
vvll dp(n + 1, vll(m + 1, inf));
FOR(i, 1, n)
{
FOR(j, 1, m)
{
if (i == j)
dp[i][j] = 0;
else
{
FOR(k, 1, j - 1)
dp[i][j] = min(dp[i][j], dp[i][k] + dp[i][j - k] + 1);
FOR(k, 1, i - 1)
dp[i][j] = min(dp[i][j], dp[k][j] + dp[i - k][j] + 1);
}
}
}
cout << dp[n][m] << "\n";
}