Ad
  • Custom User Avatar

    Time complexity is still O(len(ls)!) which is the same as the time complexity for the computing combinations. Might have a better constant prefactor.

    I don't think there is a DP way of solving this problem which usually has a time complexity of O(polynomial(len(ls))). I tried for a long time and couldn't get anywhere. The issue is that the sum is bounded by t. The familiar knapsack problem only asks that we maximize without bounds.

  • Custom User Avatar

    nevermind, I just scrolled down and saw somebody submitted this already. It was fun to learn about regex to come up with this on my own though.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution