last day (18 days later) » 

19:09
1
A: How can I write this backtracking algorithm using dynamic programming?

Apass.JackSince this question is a part of homework assignment, for which you have demonstrated substantial amount of work and progress (or non-progress), I will give an explicit and strong direction below. See if you can complete the rest. Dynamic programming is about combining optimal solutions to overl...

Thank you. However, I didn't come up to the recurrent relation. If you one in mind please let me know. Knowing $t(i,j)$ for all combinations doesn't help me, because before patroling node $i$ I had to have patroled $i-1$ by one of the officers.
Suppose we want to compute $t(i,j)$ where $i>j$. Suppose two officers just covered all points up to $i-1$ and they will reach $i$ in the next step to realize $t(i,j)$. Take a moment to think. Who covered point $i-1$? If it was the first officer, what had happened and what should happen next? If it was the second officer, what had happened and what should happen next?
It seems that we must keep track of the position of both officers because it will be fixed in any optimal solution for subproblems.
I will write my solution in my question:
I came up with a solution that is working for some sample data. It sounds valid and promising. However, I just have a little problem in describing it. I just will send it as my answer.
Can you please check my answer to see if it's what you meant?
Thank you very much. It was very useful. I guess you refined your initial definition of $t(i, j ) $. You might be agree that without the formula, getting the solution and the interpretation wasn't straightforward.
By the way, your definition of $t(i, j) $ doesn't convey that all points up to the point j were covered.
Sorry, I should have written that without loss of generality, we can assume $i<j$. Initially I did not include that trivial condition. That condition makes it somewhat easier to explain, even though it is not essential. Yes, I agree without the formula, it might be far from a complete solution. In that sense, it is cool that you have written a great solution!
By the way, I could write answer to the other question of yours. Do you want me to write an answer that includes recurrence relation overthere?
In fact, I will revert my definition back to the original one. $i<j$ is only used when I wrote the recurrence relation.
Sure that would be kind of you. I was already working on it and I gave it enough thought. I have some ideas however. Anyway your solution would complete my ideas.
19:09
It looks like you are having more fun by yourself. So I will not write anything, at least not before you have tried writing your own answer.
Not really, the due date of the assignment is close. I didn't come up a solution. As I told the constraints are too much to handle. For example, let $x = t(i,j)$ be the number of balanced trees with $i$ nodes and $j$ leaves. There are a lot of such trees and it doesn't give any number for the heights of them, unless I store the heights of each tree in another array. Anyway, the solutoin is not that clean. So, please give your solution.
To tell the truth, if this answer cannot be accepted by you (I cannot tell whether you have upvoted for it), then I am afraid even I have written the answer for that question, my answer will not be accepted as well. I felt used after I have spent a lot of work, it is considered as low quality or not acceptable even though I know it is of the highest quality, at least for some readers. Yes, although I can see the solution almost RIGHT AWAY for this kind of question, it still takes a huge amount of time to express it well enough.
Sure, the upvote was mine. For two reasons I still didn't accept it. First, even if I find a solution complete, I give it a grace time to give a chance for other users to try for an answer. Second, it seems your solution is similar the one I tested (implemented) but with a better definition. However, in my solution the second condition is when $i = j$ but you say $i=j-1$ or $i=j+1$, if we substitute the variable names. So, they differ and I must check that. Anyway, I am so grateful for the time you spent on them. If you note no one vote my own solution up or even my quesion has a down vote.
I roughly know why your question has a down vote. People here, including me, prefer pseudocode that explains ideas to actual code although running code is super useful and should be included (but as a link to some third-party website that host code) whenever available. People do not have time to read code, which is a task that is near impossible to accomplish. Without reading your code, your question becomes a question without enough detail, content or clarification. Also the presence of code suggest the question might be off-topic.
Thanks for the upvote. I am very pleased if you always give it a grace time to accept an answer (because my answer will be standing out most of time, I believe). It is even better of you to double check my answer. That will certainly help you learn!
So, I am new to this particular website. It was a nice advice and I will try to write the idea of my code using math symbols
19:09
I am going to write an explicit comment on the answer question of yours. In fact, I have said it here, "Let us construct the subproblems as simply as possible but whose solutions are strong enough to deduce the solutions of a large subproblem". The emphasis is on "subproblems are strong enough"

  last day (18 days later) »