Problem setter: aditya10_ DIFFICULTY: Medium PREREQUISITES: Dynamic Programming, Bit Masking EXPLANATION:
We will take a mask of the number of items M. 1 at ith index represent that item of type i is included. Mask at any time represents the type of items which are ordered continuously from the left. We will find the cost of adding every type of item which was not there in the mask ie the bits which were unset. Now How to find the cost of adding a type of item X? For this we will maintain an array which stores the frequency of each type of item. And a pref array pref[N+1][M+1]. pref[idx][x] represent the number of items of type x upto index idx. Author’s Solution: click here Tester’s Solution: click here asked 11 Jan, 18:16
