Understanding Dynamic Planning Divisions

Asked 2 years ago, Updated 2 years ago, 95 views

Below is the problem of determining the number of divisions using dynamic planning.
The following dp arrangement is defined and a gradualization formula is used to solve this problem, but there are three things I don't understand.I am not good at translating questions into languages, but I would appreciate it if you could explain them.

I understand that you think as shown in the example below, but I assign one to each set, but below that, I assign 6,0,0,0,0,0. Is that okay?
e.g. For patterns that divide 10 into 4 pieces, there are 4 sets first, so assign 1 to each set
1,1,1,1
After that, the number of patterns for allocating the remaining six to the four sets can be considered.
For example,
6,0,0,0
1,1,1,3
2,2,0,2

The overall dynamic planning image is missing.

dp array: dp[i][j]: sum of i divisions of = j
Graduation formula: dp[i][j]= dp[i][j-i]+ dp[i-1][j]

Find the sum of how to divide n indistinguishable items into m or less and answer how much divided by M.

  • Enter

    n=4
    m=3
    M=10000

  • Output

    4(1++2=1+3=2+2=4)

Input

n=4
m=3
M = 10000

Output

4(1++2=1+3=2+2=4)

Browse: Programming Content Challenge Book

algorithm

2022-09-30 21:39

1 Answers

If you match the meaning of the dp array to the expression in question,
dp[i][j]=> Sum of how to divide j into i or less
Yes. If you combine terms other than unknown terms dp[i][j-i] in the incremental formula with this expression,
dp[i][j] (sum of how to divide j into i or less) = dp[i][j-i]+dp[i-1][j] (sum of how to divide j into i-1 or less)
In other words, dp[i][j-i] appears in the asymptotic expression as sum of how to divide j things into 'just i'.

The following is a list of

"Split 'i or less' into 'i sets' where 'element may contain 0 sets'
"Split 'just i' into 'i's set without zero elements"

Let's move on with the same way.

Assuming this is the case,

1. The idea of incremental dp[i][j-i] seems to be to assign i pieces one by one to the set of i pieces and assign the remaining j-i pieces to this set, but I don't know why.

To ensure that all i sets contain at least one object, so that it is divided into 'just i pieces'.

2. I understand that you think as shown in the example below, but would it be alright if you assign 6,0,0 and 0 to each set?

By thinking like this, you can prove that dp[i][j-i] is the same number as "the sum of how to divide j things into 'just i' pieces."

"·First of all, even if there are zero sets of elements in the division before adding one, there will be no zero sets of elements, so you can see that "" elements are divided into zero sets"" after adding one to all of them."

·On the other hand, if you are thinking of splitting into i sets with zero elements, you can see that you can remove one from all sets and restore the original \"'i set with zero elements\" (*If this is all i in the challenge book, ai>0 represents {ai-1} as n-m m).

In other words, by adding (or removing) one to all sets of zero elements, you can match "j-i divided into i or less" and "j divided exactly i divided" one-to-one.

dp[i][j-i]= Sum of how to divide j into 'just i'

You can prove the .

3. I don't have the overall image of dynamic planning.

Although it is not limited to dynamic planning, the basic idea is to solve the problem by breaking it down into a small problem that is easy to solve and using the solution to solve the original problem.Dynamic planning is one of these algorithms where small problem solutions can be written down and calculated quickly when the same problem needs to be solved over and over again.

Dynamic planning is often done by bottom-up (calculating small problems and then working on big ones) like the one in the challenge book, but that's not an essential part.
If the image is particularly difficult to grasp, I think it would be easier to grasp the image if you tried to solve it using a top-down method (such as solving small problems if necessary using recursive calls of functions).Smaller problems can be solved without taking notes, and even slightly larger problems can be expected to have the same performance as bottom-up.

But knowing this doesn't mean you can master dynamic planning.It's easy to do in the challenge book, but how to break it down and solve the original problem from the result of the break it down is inherently difficult.


2022-09-30 21:39

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.