1

Topic: Re: the Finding of the second, the third result

Hello, Helkar, you wrote: the Task: There is an array of arrays of integer numbers. It is necessary to find n minimum totals selecting on one element from each array. The n-minimum totals should be a miscellaneous? We take also everyone on a minimum element and it is added. I invented algorithm, but such sensation that owed a life  someone to me. I ask the help in finding of suitable algorithm. And where that invented the description of that?

2

Re: Re: the Finding of the second, the third result

Hello, Helkar, you wrote: the Problem not in the least total, and in that how to receive the second, the third and so on the least. It is enclosed in the description and I yet did not check up it, therefore I want to ask at first here not to invent a bicycle. An example result: m [1 =1 2 2 3 4 5 m [2 =1 2 3 4 7 m [3 =2 3 4 5 m [4 =4 4 4 S [1] =1+1+2+4=8 S [2] =2+2+3+4=11 S [3] =3+4+4+4=15 So?

3

Re: Re: the Finding of the second, the third result

Hello, kov_serg, you wrote: _> Hello, Helkar, you wrote:>> the Problem not in the least total, and in that how to receive the second, the third and so on the least.>> It is enclosed in the description and I yet did not check up it, therefore I want to ask at first here not to invent a bicycle. _> an example result: _> _> m [1 =1 2 2 3 4 5 _> m [2] =1 2 3 4 7 _> m [3 =2 3 4 5 _> m [4] =4 4 4 _> _> _> S [1] =1+1+2+4=8 _> S [2] =2+2+3+4=11 _> S [3] =3+4+4+4=15 _> _> So? And why the second not 1+2+2+4?

4

Re: Re: the Finding of the second, the third result

Hello, T4r4sB, you wrote: _>> Hello, Helkar, you wrote:>> the Problem not in the least total, and in that how to receive the second, the third and so on the least.>> It is enclosed in the description and I yet did not check up it, therefore I want to ask at first here not to invent a bicycle. _>> an example result: _>> _>> m [1 =1 2 2 3 4 5 _>> m [2 =1 2 3 4 7 _>> m [3 =2 3 4 5 _>> m [4 =4 4 4 _>> _>> _>> S [1] =1+1+2+4=8 _>> S [2] =2+2+3+4=11 _>> S [3] =3+4+4+4=15 _>> _>> So? TB> And why the second not 1+2+2+4? And why not 1+1+2+4 each time? What restrictions?. Already taken element can be used repeatedly, or not? Or it would be necessary simply that the totals grew?

5

Re: Re: the Finding of the second, the third result

Hello, kov_serg, you wrote: _> And why not 1+1+2+4 each time? _> what restrictions?. Already taken element can be used repeatedly, or not? Or it would be necessary simply that the totals grew? If it is impossible to take repeatedly, why S [3] not 2+3+4+4?

6

Re: Re: the Finding of the second, the third result

Hello, T4r4sB, you wrote: TB> Hello, kov_serg, you wrote: _>> And why not 1+1+2+4 each time? _>> what restrictions?. Already taken element can be used repeatedly, or not? Or it would be necessary simply that the totals grew? TB> if it is impossible to take repeatedly, why S [3] not 2+3+4+4? It is a misprint. There there should be columns m [1 =1 2 2 3 4 5 m [2 =1 2 3 4 7 m [3 =2 3 4 5 m [4 =4 4 4 S [1] =1+1+2+4=8 S [2] =2+2+3+4=11 S [3] =2+3+4+4=13

7

Re: Re: the Finding of the second, the third result

Hello, Helkar, you wrote: the Task: There is an array of arrays of integer numbers. It is necessary to find n minimum totals selecting on one element from each array. It is possible to solve by means of queue on priorities (there will be a certain overhead projector on storage) to Sort all arrays to Suppose in queue a dial-up of zero indexes with total Sum (0,0,0...) = A [0 [0] + A [1 [0]... + A [N-1] [0] Cycle K of times: to Derive a dial-up c a minimum total (i0, i1, i2...) to Suppose in queue all following dial-ups-candidates (i0 + 1, i1, i2...) (i0, i1 + 1, i2...) (i0, i1, i2 + 1...)... For a case of two arrays somewhere there was the linear algorithm, but whether it is scaled on the arbitrary amount of arrays -

8

Re: Re: the Finding of the second, the third result

Hello, Helkar, you wrote: TB>>> And why the second not 1+2+2+4? _>> And why not 1+1+2+4 each time? _>> what restrictions?. Already taken element can be used repeatedly, or not? Or it would be necessary simply that the totals grew?> All is correct, it is possible to use the taken element repeatedly, but it is necessary that the totals grew. And what to do with the identical totals, but different elements?

9

Re: Re: the Finding of the second, the third result

10

Re: Re: the Finding of the second, the third result

Hello, Helkar, you wrote: the Task: There is an array of arrays of integer numbers. It is necessary to find n minimum totals selecting on one element from each array. I invented algorithm, but such sensation that owed a life  someone to me. I ask the help in finding of suitable algorithm. Sort all arrays. Take from each 0th element. In each following total it is possible to use the elements involved in the previous total? If it is impossible - shift an array with maximum of 0 elements (to move elements it is not necessary, it is necessary to change a beginning index). Repeat for the following. On forget about the sizes of arrays.

11

Re: Re: the Finding of the second, the third result

Hello, Kodt, you wrote: And not to speak "at achievement of the end of a dial-up, to drop in the beginning" - give we add in each of them certainly big garbage - 100500, 200600, 300700 any. Can find at first the totals, and then under the given total of a chain to make, in process of requests

12

Re: Re: the Finding of the second, the third result

Hello, Kodt, you wrote: Hello, AleksandrN, you wrote: No. Sometimes it is necessary to take a step back. An example: [0,100,200], [0,10,20..., 90], [0,1,2... 9] it is clear, to what I conduct? 0+90+9, then 100+0+0 yes. Was mistaken. At a finding of everyone minimum it will be necessary to take steps back and to look different variants, whence to take the following element. But exponential computing complexity of algorithm turns out.

13

Re: Re: the Finding of the second, the third result

Hello, Kodt, you wrote: Hello, kov_serg, you wrote: And it is possible with explanations? _>> https://ideone.com/GTaAms I here see - amateur implementation bisect.bisect inside next, two times - amateur implementation of the generator and itertools.islice (it  take) inside combine - a choice from 4 variants, and, for some reason, with rollbacks on 1 position back (why on 1 position?) Here that becomes? def creep (A, B, i, j): S=A [i] +B [j] s0=best (next (S, A, B, i, j-1), next (S, A, B, i, j+1)) s1=best (next (S, B, A, j, i-1), next (S, B, A, j, i+1)) res = best (s0, (s1 [0], s1 [2], s1 [1], s1 [3])) return res Here it is searched the least following candidate for total S' = A [i '] +B [j ']> S=A [i] +B [j], S'-> min 1 2 3 4 5 6 7 8 9 [A] 1 2 3 4 - 6 7 - - A 2 - - - - - - - / - 3 - - - - - - / - - 4 5 6 7 - 9 (A) - - * 5 - - - - / - - - - 6 7 8 9 / B D - - F 7 - - / - - - - - - 8 - / - - - - - - - 9 A/B a C - E F - - 12 [B] A = [1,2,3,5,6,9] B = [1,4,6,9] In grid A [x] +B [y] the following Choice is based on the least following total A [x] +B [y]/A+B=const / / (1) / | 1-------- + | / | (3) - to the right, (4) - downwards and under a diagonal (the equal total) but to them it is necessary to creep. Search is replaced with a dichotomy.

14

Re: Re: the Finding of the second, the third result

Hello, Kodt, you wrote: Here me something strongly confuses this place. The isoline of the equal total - it, of course, monotonous, but can be somehow bent. Whether successive approximations are necessary here? Yes you are right. Constructed  an example. It is necessary to alter function creep. Generally it is necessary to be pressed along all isoline, and in criterion of a stop to add S=So+1

15

Re: Re: the Finding of the second, the third result

16

Re: Re: the Finding of the second, the third result

Hello, Tyomchik, you wrote: Those> Objasnite stupid, here the total should grow, on each step to be returned back for each array. After all it is not important,  you there , even if and log n, but that for each array - it log (n) ^ m. And still m* n * log (n) for preliminary sorting. When at us arrays of integer numbers, instead of real. In what a question? M arrays no more K elements, we select the first N that on time without  ~ M * (K*ln (K) + N^2*ln (N)) simply it would be desirable an expense  the second item.