algorithm - Splitting 61 into integer partitions -


in program doing, have vector called a = [5, 6, 7] , have split integer 61 additive partitions using integer list. 1 example be

61 = 5 + 6 + 7 + 7 + 6 + 6 + 6 + 6 + 6 + 6 

there many ways split this. have programmatically. 1 approach found follows. don't know if give result. first check if 61 divisible number in list. if is, can use number add many times (i.e. quotient) 61. in case, 61 prime number. fail. next step take first number in list (in our case, 5) , subtract 61 , try see if answer divisible member in list. if is, again found way addition. in case, subtracting 5 61 gives 56, divisible 7 , our solution be

61 = 5 + 7 + 7 + 7 + 7 + 7 + 7 + 7 + 7 

in manner continue down list until find answer after subtraction divisible member in list.

now given list me, [5, 6, 7] such there exists integer partition such that, can 61 additions using integer partition. won't have worry whether solution exists. approach seems crude. wonder if there efficient way using algorithm combinatorics. final answer should list of numbers integer partition. 1 possible answer be

[5, 6, 7, 7, 6, 6, 6, 6, 6, 6] 

thanks

the generic root of 61 7

multiple of 7 nearing 61 8 hence , subtracting 61-7*8 =gave 56,

similarly multiple of 6 nearing 61 gap of 7 9, subtracting 61-6*9 =gave 54,then result % remaining 2 {5,7} satisfied should zero

getting intermediate sum , finding generic root combined displacement can give answer.

hope helps. !! happy further


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -