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

Автор Death_Scythe, история, 10 лет назад, По-английски

Hi all!

I don't have the exact problem statement, it was asked in one of the coding tests for an interview but I think I remember the problem quite well.

Given an array of n values, we have to make two sets such that size of first is at most k and size of second is at most s. The difference of sum of values in first set and sum of values in second set is minimum. I need to find this minimum value.

The sets must be non-empty.

Constraints: n<=200, k,s<=100, 0<values in array<=1000

Please let me know if something is unclear.

Thanks!

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

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

Can they have common elements?

»
10 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +11 Проголосовать: не нравится

for every element try to put it in the first set if cur_size_of_first_set+1 <= k or put it in the second set if cur_size_of_second_set+1 <= s and check the difference in every step .. your statue is dp[pos][difference][cur_size_of_first_set_size][cur_size_of_second_set_size] I think this approach will work but I don't know if the complexity is good or if we can do any optimization on it !

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

Auto comment: topic has been updated by Death_Scythe (previous revision, new revision, compare).