algorithm - Min number of Elements To generate all other elements using xor -


i have n integers a_1, ..., a_n. want pick minimum number of them xor forms others.

for example, consider [1,2,3], 1^3=2 don't need 2 in array. can remove it. end [1,3]. min number of elements 2 , can form original elements in array xoring 2 of them. greedy approach work here? or dp?

edit: explain thinking. greedy approach thought due fact if a^b=c a^c=b , b^c=a. first delete duplicates. first in beginning list pairs each element can pair form element in array. takes o(n^3) preprocessing. pick element least contribution , delete , subsequently subtract 1 each of other elements. repeat until elements have <=2 pairs. , stop. take o(n^3) total of o(n^3). greedy approach work? there dp way it?

if n bounded 50 think backtracking should work.

suppose @ step have selected subset s of numbers (that should produce others) , want include new number subset. can following:

  • consider remaining numbers r , include in s numbers can't produced others (in s , r)
  • include in s random (or "best" in way) number r
  • remove r numbers can produced in updated s

also should keep track of current best solution , cut off branches won't allow better result.


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -