Brackets all over problem not able to solve

BRACKETS ALL OVER … please help in this problem

@checkmate112
Use recursion and optimise it using memoization.
Time complexity will be O(n*(n-m))