How to solve this problem using Dp ??? I read the editorial and found that it has been solved using combinatorics but I saw others have solved it using Dp approach.
Problem Link -https://mirror.codeforces.com/contest/1288/problem/C
Please Help !!!! Thanks in advance
At first,we reverse array B and make array B is non-descending.It is easy to find that if array A and array B combine to form array C, array C is non-descending.Therefore, the answer is equal to the number of non-decending array C whose element is an integer between 1 to n.(The length of array C is 2*n).We assume dp[i][j] means the number of array C whose length is i and maximum value is j.So the answer of this problem is dp[2*m+1][n].The dp function is:
dp[i][j]=dp[i-1][1]+dp[i-1][2]+...+dp[i-1][j] So the complexity is O(n*n*m).Since the constraint is too weak.This method is correct.But if the constraint is stronger,you should used some data structure to reduce the time of dp function.
It is my code:
Thank you so much !!!! Also One doubt that why the final answer will dp[2*m+1][n] , it should be dp[2*m][n] as the final length of the array will be 2*m ???
Because dp[i][j] means the number of array C whose length is i and maximum value is j,final answer = dp[2*m][1]+ dp[2*m][2]+...+dp[2*m][n],which is equal to dp[2*m+1][n].
use dp or combinatorics
You may take a look at this solution