Блог пользователя TangyStone8

Автор TangyStone8, история, 5 лет назад, По-английски

I always find myself looking at the solution for DP problems after spending an hour or so. This has happened many times, and yet I haven't developed any routine for detecting and solving the DP problems. Even when I do detect that the problem is DP, I struggle with the solution. What do I do to develop a thought process to solve DP ?

  • Проголосовать: нравится
  • +6
  • Проголосовать: не нравится

»
5 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

This is what I think when I try to think of a DP approach for any problem.

  1. What are the parameters which completely define the current state?
  2. How can I make transitions from one state to another?
  3. Is there any base cases that need to handled separately?

Harder problems require some further optimizations as well.

»
5 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Just solve more DP problems :P. It comes with practice, there is no shortcut.

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Back when I was a specialist, I had a very crude way of figuring out whether a problem is DP or not: try a greedy first and if it doesn't work (or you can't find a greedy solution), then maybe DP is the solution. After a lot of practice, feeling on identifying a DP problem becomes a bit of a gut feeling (but I still think that DP can many times easily handle cases where a greedy solution either miserably fails or is very hard to create).

Regarding the thought process, the way I do it is to first look at what parameters should be considered to describe the states, then defining the DP (write down what dp[i][j] precisely means). Afterwards, to find out the recurrence, I suppose that I magically found out the values of the previous states and then determine how the current state (or future state) depends on these previous states. Don't forget to look at the problem constraints (like n, m, etc.) which can sometimes give you a hint of where to start or how many states the DP could have.

»
5 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

You need to use your brain

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

I'm curious, whats the maximum number of these blogs that's been made? 100? 200?

Anyways,

Step 1. Solve all standard cses dp problems / Read online editorials. Step 2. Profit.