Home > Net >  A simple algorithm
A simple algorithm

Time:09-27

Ask a question, as follows:
A number of Y can be divided into certain number in the list, make some number in the list, and some number is equal to the sum of Y
Example:
List: 2000300 0400 0800 0200 00400 00600 00
Y=20000, Y in the list, if divided into ten digits of a maximum number of 4 results can be as follows:
4000800 {0800} {20000}
Y=20000, Y in the list, if divided into the maximum number of ten number is set to 5, the results can be as follows:
{2000200 0400 0400 0800 0} {0800} 4000800 {20000}
Y=40000, Y in the list, if divided into the maximum number of ten number is set to 5, the results can be as follows:
{4000400, 0800, 0400, 0200 00} {00 2000200 0800 0800 0200} {40000} {20000200}
Multiple results, returns a random can

CodePudding user response:

The simplest algorithm: the number/10 *, output & lt; Of the part and the rest, such as: 20000/10=2000200 0200, 0140, 00;
40000/10=4000400, 0400, 0400, 0240 00;

CodePudding user response:

reference 1/f, the wise know already should good karma response:
the simplest algorithm: the number/10 *, output & lt; Of the part and the rest, such as: 20000/10=2000200 0200, 0140, 00;
40000/10=4000400, 0400, 0400, 0240 00;

Hello, 14000 and 24000 are in the list

CodePudding user response:

Give you write a simple algorithm for your reference, can also be further amended as binary, top ten ideas is not wrote
 
Int [] a={2000, 3000, 4000, 8000, 20000, 40000, 60000};
Int=4 aa, aaa=20000, b=0, bb=0;

While (bBb=aaa - a [b] * (aa - 1);
if (! A.C ontains (bb)) + + b; else break;
}

CodePudding user response:

Give you write a simple algorithm for your reference, can also be further amended as binary, top ten ideas is not wrote
 
Int [] a={2000, 3000, 4000, 8000, 20000, 40000, 60000};
Int=4 aa, aaa=20000, b=0, bb=0;

While (bBb=aaa - a [b] * (aa - 1);
if (! A.C ontains (bb)) + + b; else break;
}

Simple algorithm can satisfy the general section (20000/4200 00/5400 00/5400 00/6, but cannot be realized 40000/4),
Improve algorithm can satisfy more reasonable section (40000/4=20000 + 8000 + 8000 + 4000)

Above to prepare to remove the data and variables, calculation is only for sentence: while (bBb is to debug observation, the actual use can save,

Instead of nested loop can be more reasonable, is not the best algorithm, optimal algorithm should be a full array of permutation and combination elements, can fully realize various combinations, to avoid omissions, this idea is just draft,
  •  Tags:  
  • C#
  • Related