Atcoder Problem

Please explain solution to this problem-


I used simple Brute Force to solve this problem. Here is my code.


Notice that N is just 8 in the worst case. This provides one a hint to try Brute Forcing. Basically, all I did was - for every bamboo, I decided to either :

  1. Not use it, or
    2)Use it to form A, or
  2. Use it to form B, or
  3. Use it to form C

I did this recursively and took the minimum cost of all possible combinations.
Feel free to ask if something is unclear.

Hope this helped :slight_smile:

yeah got it!!.. thanks a lot.