Home > Back-end >  Are there other ways of multi-layer cycle? 100 layers loop 100 times I want to write FOR?
Are there other ways of multi-layer cycle? 100 layers loop 100 times I want to write FOR?

Time:09-20

Today, do a little thing when meet a problem, don't know is what you want to enter into a dead end or situation, think that should not be so, but I don't remember there are other ways,
Question is like this, a flat surface, a total of 12 position, have a special connection between position and location, despite a fixed structure remains the same, 11 other each location are likely three different buildings, buildings with different attachment will produce different results, and then I'm going to work out that way is the best , played the game the students should know what I say, the answer would have had just want to see, but found a total of 11 layers, to write for 11 times, then I don't know have no easy way to... The appended drawings below

CodePudding user response:

combinations of a total of 3 ^ 11 11 power (3), you can use the recursive calculation,

CodePudding user response:

Can use the queue, or recursion

CodePudding user response:

refer to the second floor met the goddess response:
combinations of a total of 3 ^ 11 11 power (3), you can use the recursive calculation,


reference Italink reply: 3/f
can use queue, or recursive



 int []=p,1,1,1,1,1,1,1,1,1,1,1 {1}; 

For (p [0]=1; P [0] <4. P + + [0])
{
For (p [1]=1; P [1] <4. P + + [1])
{
For (p [2]=1; P [2] <4. P + + [2])
{
For (p [3]=1; P [3] <4. P + + [3])
{
For (p [4]=1; P [4] <4. P + + [4])
{
For (p [5]=1; P [5] <4. P [5] + +)
{
For (p [6]=1; P [6] <4. P + + [6])
{
For (p [7]=1; P [7] <4. P + + [7])
{
For (p [8]=1; P [8] <4. P + + [8])
{
For (p [9]=1; P [9] <4. P + + [9])
{
For (p [10]=1; P [10] <4. P + + [10])
{
K=Zonghe (0, 0, 0);
K=qiuhe (k, p);
Zonghe guding=Zonghe (0, 0, 0);

for (int i=0; i <11. I++)
{
If (p==y [I])
{
Guding. Yule=guding. Yule + 1;
}
If (p==f [I])
{
Guding. Renkou=guding. Renkou + 10;
}
If (p==g [I])
{
Guding. Yule=guding. Yule - 1;
}
}

Kz=k + guding;

If (kz. Yule & gt;=0)
{
If (diyige==0)
{
Zui=kz;
Diyige=1;
}
The else
{
Zui=bia (zui, kz, p);
}
}




}
}
}
}
}
}
}
}
}
}
}
think along while still don't know how recursive...

CodePudding user response:

This is a problem of permutation and combination
Can need not recursive, changing the for loop to (carry) it is ok to use array
11 position, such as the following program is equivalent to print each position is {0} three elements of the portfolio)
Int main ()
{
Int I, [11] CNT={0};//11 layer with an array of management circulation, assuming that the maximum number of circulation loop on each floor for 3
While (CNT [0] <3)//when the outermost loop count is less than the maximum number of cycle continues to cycle (that is equivalent to the outermost for haven't continue at the end of the cycle)
{
for (i=0; i<11. I++)
{
Printf (" % d ", CNT [I]);//print the current of each layer of circulation loop count
}
printf("\n");

CNT [10] + +;//the last layer of circulation loop count incrementing
For (I=10; I> 0; I -)//use of the method of simulation carry (maximum + 1 is high, low low qing 0)
{//equivalent to two layers for the I, j loop, j++ minor cycle ahead, will be increasing i++ circulation, then tiny j continue to start from 0
If (CNT [I]==3)//if the loop count reached the maximum cycle
{
[I] CNT=0;//the current layer loop count from scratch
CNT [I - 1] + +;//on a layer of increasing cycle count
}
}

}
}

CodePudding user response:

Use unlimited nested

CodePudding user response:

ginseng fruit reference 4 floor puzzling response:
Quote: refer to the second floor met the goddess response:

combinations of a total of 3 ^ 11 11 power (3), you can use the recursive calculation,


reference Italink reply: 3/f
can use queue, or recursive



 int []=p,1,1,1,1,1,1,1,1,1,1,1 {1}; 

For (p [0]=1; P [0] <4. P + + [0])
{
For (p [1]=1; P [1] <4. P + + [1])
{
For (p [2]=1; P [2] <4. P + + [2])
{
For (p [3]=1; P [3] <4. P + + [3])
{
For (p [4]=1; P [4] <4. P + + [4])
{
For (p [5]=1; P [5] <4. P [5] + +)
{
For (p [6]=1; P [6] <4. P + + [6])
{
For (p [7]=1; P [7] <4. P + + [7])
{
For (p [8]=1; P [8] <4. P + + [8])
{
For (p [9]=1; P [9] <4. P + + [9])
{
For (p [10]=1; P [10] <4. P + + [10])
{
K=Zonghe (0, 0, 0);
K=qiuhe (k, p);
Zonghe guding=Zonghe (0, 0, 0);

for (int i=0; i <11. I++)
{
If (p==y [I])
{
Guding. Yule=guding. Yule + 1;
}
If (p==f [I])
{
Guding. Renkou=guding. Renkou + 10;
}
If (p==g [I])
{
Guding. Yule=guding. Yule - 1;
}
}

Kz=k + guding;

If (kz. Yule & gt;=0)
{
If (diyige==0)
{
Zui=kz;
Diyige=1;
}
The else
{
Zui=bia (zui, kz, p);
}
}




}
}
}
}
}
}
}
}
}
}
}
think along while still don't know how recursive...



 # include & lt; Iostream> nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull           
  • Related