Блог пользователя Pororo789

Автор Pororo789, история, 5 лет назад, По-русски

how to solve this problem:

given a n — numbers of players and their height h_i. You need to split to k teams that the incompatibility is minimal. Incompatibility is the sum of the mx(maximum height of team player)-h_i(height of other player)

n <= 10^5

k <= min(n,20)

h_i <= 10^6

  • Проголосовать: нравится
  • -4
  • Проголосовать: не нравится

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Please give sample input/output and its explanation to understand the problem better.

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Give some example input and result (or a link to the original problem) cause I'm not sure if I understand the problem properly. This is my idea: 1) Sort all the players by their heights increasingly. We can assume that the best solution always put players with similar heights to one team (because it's optimal) so our problem is just to divide this sorted array into segments. If some players should be in one team, they're consecutive segment in the array. 2) Calculate prefix sums for the sorted array. It let us to count incompatibility of a given team in O(1) 3) Apply dynamic programming to two-dimensional array with n columns and k rows. The solution will be in left-down corner of the array. Complexity is O(k*n). I think it's enough as it needs at most 2*10^6 operations.