Staircases - Timus 1017
Maintain a function with current position(column) of the staircases($i$) , number of remaining block($r$) , number of block we have used for the last column($l$).
for $i^{th}$ position we can use $x\in [1,min(r,l-1)]$ block in this step.
But if we use dp table of $500 \times 500 \times 500$ size it will cause you MLE.
Notice that, we dont need position($i$) here, only things we need here if $i$ is greater than $1$ or not. Hence we can minimise $i$ with $2$. Then size of our dp table will be $2 \times 500 \times 500$ .
But actually we don’t need $i$ for this code. But Why?
The code will be like this:
Reference:⌗
Read other posts