The following is my code, can you tell me what’'s wrong with it? https://ide.codingblocks.com/s/428070
Please help me with my code
I cannot completely understand your logic but there is a flaw.
Your code throws runtime error, so reduce your dp vector size to 3005 X 3005.
Now your code gives wrong answer for testcase
4
2 3 4 2
It gives 5 as answer whereas answer should be 1.
So this is how I have solved the question. https://ide.codingblocks.com/s/428147
So Taro intends to maximise X-Y, so he will try to maximise the sum he can accumulate.
dp[index_1][index_2] is the answer for this range.
We can write it as
dp[index_1][index_2] = max(a[index_1] - solveDp(index_1 + 1, index_2), a[index_2] - solveDp(index_1, index_2 - 1));
Each player tries to maximise this quantity for himself. Just dry run this and you’ll understand.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.