java - printing partitioned set in partition prob -


in partition problem have understood pseudo polynomial time algorithm.but not able print balanced set .

i not able figure out store instead of boolean values in table constructed algo.

please provide algo print partitioned subset also.

can provide solution in can modify table constructed achieve partitioned values.

solving partition problem based on formulas:

d(i,0) = true d(0,x) = false if x!=0 d(i,x) = d(i-1,x-arr[i]) or d(i-1,x) 

in order reproduce actual element can store matrix, indicated if element taken or not, let matrix q.
in other words, q(i,x) = true if , if d(i-1,x-arr[i]) = true.

now, can reproduce set with:

set1 = {} set2 = {} x = sum/2 n 0 decreasing:    if q(i,x):       x = x - arr[i]       set1.add(arr[i])    else:       set2.add(arr[i]) 

an alternative not require constructing second matrix q, , instead retraces steps. basic idea similar previous one.

set1 = {} set2 = {} x = sum/2 n 0 decreasing:    if d(i-1,x-arr[i]):  //   ^^ condition changed ^^       x = x - arr[i]       set1.add(arr[i])    else:       set2.add(arr[i]) 

the idea similar, if adding element valid solution, add set, it's part of partition. otherwise, it's not part of partition.


Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -