Home > Net >  Pray for all solution to a diversity of a?
Pray for all solution to a diversity of a?

Time:10-08

What method can efficiently calculate all solution to a diversity of a?
For example, X1 + X2 +...... + X26=51;

All integer solutions for each solution range between 0 to 10,

CodePudding user response:

51 1, divided into 26 heap,

CodePudding user response:

If allowed to decimal or negative, should be an infinite number of solutions, allowing only positive integer, directly with backtracking method

CodePudding user response:

reference wangyx92528 reply: 3/f
if allowed to decimal or negative, should be an infinite number of solutions, allowing only positive integer, directly with backtracking method

Allow the integer 0 to 10, including 0, 10, and I tried once, seem to have hundreds of millions of solution, calculating up slowly, so ask the great spirit is there any good way,

CodePudding user response:

There is no way, this belongs to "heaps number theory" -- -- -- -- -- -- -- - hua luogeng gentleman's study,

The ans only a back iteration, and a solution is easy, to all traversal, can ah, threw COINS, let his hair into mining tasks, the mining machine to calculate to

CodePudding user response:

But to solve fairly easy

10 + 10 + 10 + 10 + 10 + 1

First 5, 10, 5 points with straight line, quite a divided into 6

Now is the remaining 21 points, random thrown into the region of 5 and 10

Actually, of course, the problem is simplified into 10 this number is can be divided into how many group

Finally back into a 1 + 1 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- this is the research scope of hua luogeng old gentleman

CodePudding user response:

The subject didn't read it, fixed X1 to X26? It can't be integers from 1 to 10 is already 55.

CodePudding user response:

refer to 7th floor java__net response:
the topic not understand, fixed X1 to X26? It can't be integers from 1 to 10 will have 55.

Not fixed can be 10 + 10 + 10 + 10 + 1 + 0... + 0=51,
Can be zero,

CodePudding user response:

refer to 6th floor wanghui0380 response:
"to solve fairly easy

10 + 10 + 10 + 10 + 10 + 1

First 5, 10, 5 points with straight line, quite a divided into 6

Now is the remaining 21 points, random thrown into the region of 5 and 10

Actually, of course, the problem is simplified into 10 this number is can be divided into how many group

Finally back into a 1 + 1 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- this is the research scope of the hua luogeng old gentleman

Well actually in order to solve a business problem, think of a way, but seems not possible, see if there are other ways to solve,

CodePudding user response:

X is a number between 0 and 10 other random combination

CodePudding user response:

The X1 + X2 +...... M + Xn=
Xn [0, M] integer values,

Define an array X [n - 1) temporary the value of X,

Define an iterative function, parameters include:
N - a few yuan,
M - and the rest can be used to integer,
Function return early conditions:
M=0, the rest of the X is 0,
Or n=1, this time Xn=M,

51, M=n=26 should not how long can the whole iteration,

CodePudding user response:

And all positive integer solutions can only use enumeration, 26 unknown each unknown values range (0-51) 26 nested loops, each loop cycles on 51, 51 of the total of 26 power, enumeration result is less than this number

CodePudding user response:

refer to 7th floor java__net response:
the topic not understand, fixed X1 to X26? It can't be integers from 1 to 10 will have 55.

The range is 0 to 1, 0

CodePudding user response:

Borrow floor lift to ask: n degree univariate polynomial equation, (n=26) of the building Lord, if I don't know the value of n in advance, n as a variable, so how to write the cycle

CodePudding user response:

refer to 12 floor jx315425246 reply:
and all positive integer solutions can only use enumeration, 26 unknown each unknown values range (0-51) 26 nested loop, each loop cycles on 51, 51 of the total of 26 power, enumeration result is less than the number of


Borrow floor do bosses: n degree univariate polynomial equation, (n=26) of the building Lord, if I don't know the value of n in advance, n for variables,

Means n cycle, so how to write code

CodePudding user response:

The
reference 11 floor wid999 response:
X1 + X2 +...... M + Xn=
Xn [0, M] integer values,

Define an array X [n - 1) temporary the value of X,

Define an iterative function, parameters include:
N - a few yuan,
M - and the rest can be used to integer,
Function return early conditions:
M=0, the rest of the X is 0,
Or n=1, this time Xn=M,

51, M=n=26 should not how long can the whole iteration,



Borrow floor do bosses: n degree univariate polynomial equation, (n=26) of the building Lord, if I don't know the value of n in advance, n for variables,

Means n cycle, you how to write code that

CodePudding user response:

reference 15 floor lxl126 response:
Quote: refer to 12 floor jx315425246 reply:

And all positive integer solutions can only use enumeration, 26 unknown each unknown values range (0-51) 26 nested loop, each loop cycles on 51, 51 of the total of 26 power, enumeration result is less than the number of


Borrow floor do bosses: n degree univariate polynomial equation, (n=26) of the building Lord, if I don't know the value of n in advance, n for variables,

Means n cycle, so how to write code


Then use recursion, n recursive

CodePudding user response:

If an integer is tantamount to put all the value of the exhaustive,

For example, 56 1

And each value 0-10 and the extra digits 0.

CodePudding user response:

Also want to thank you for your reply ~ ~ before, only the recursive method, but the use recursion may be difficult to achieve, feel recursive also implement A! This kind of question,


For example:
Known four yuan a equation x1 + x2 + 3 x3 + 2 x4=6, 5 lists all the possible natural number solution
https://ask.csdn.net/questions/766857
#! The/usr/bin/python
For the x1 in range (0, 7) :
For the x2 in range (0, 7) :
For the x3 in range (0, 7) :
For x4 in range (0, 7) :
If x1 + x2 x3 + 5 + 3 * 2 * * x4==6:
Print (STR + "" + STR (x1) (x2) +" "+ STR (x3) +" "+ STR (x4) +" "+ STR (2 + 3 * * * * x1 x2 + 4 x3 + 5 * * * * x4));


This is very difficult to write, using a recursive begged god give directions

CodePudding user response:

refer to 17th floor jx315425246 response:
Quote: reference 15 floor lxl126 response:

Quote: refer to 12 floor jx315425246 response:

And all positive integer solutions can only use enumeration, 26 unknown each unknown values range (0-51) 26 nested loop, each loop cycles on 51, 51 of the total of 26 power, enumeration result is less than the number of


Borrow floor do bosses: n degree univariate polynomial equation, (n=26) of the building Lord, if I don't know the value of n in advance, n for variables,

Means n cycle, so how to write code


nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related