From the topic, this feeling is good to go around. In fact, I should have expressed a problem.
For example:
1,[],1
2,[],[]2
In this way, there are a few pits between the two identical numbers.
In fact, this array calculation is not too large. If the reasoning ability is good, it can be solved in minutes.
Here I want to achieve the purpose through the program:
1, in order to dream this realization process, the ideological struggle for a night did not sleep, the kind of poor lifting method is better. In fact, I have not written a poor lift. (--really think too much)
2, understand the poor lifting algorithm. (I don't know if the method I'm writing below is too poor.) haha
first we have to have a train of thought. "Poor to cite all possible permutations." = Rule matches the required array = output "The
first step: poor lifting
My first mistake of the implementation method, I also write to not be afraid of shame (hehe). That's the way it is:
Since there are eight locations. Then do not consider the case of duplication. (That is, it is not the same by default)
Let's define eight strings first.
1 string[] STRs =New string[8] {"X1","X2","X3","X4","X5","X6","X7","x8" };2 string[] temp =New string[8];3 intx=0;4 for(inti =0; I < STRs. Length; i++)5 {6temp[0] =Strs[i];7 for(intI1 =0; I1 < STRs. Length; i1++)8 {9 if(temp[0]!=Strs[i1])Ten { Onetemp[1] =STRS[I1]; A for(intI2 =0; I2 < STRs. Length; i2++) - { - if(temp[0]! = strs[i2]&&temp[1]!=Strs[i2]) the { -temp[2] =Strs[i2]; - for(inti3 =0; i3 < STRs. Length; i3++) - { + if(temp[0] = Strs[i3] && temp[1]! = strs[i3]&&temp[2]!=Strs[i3]) - { +temp[3] =Strs[i3]; A for(intI4 =0; I4 < STRs. Length; i4++) at { - if(temp[0] = Strs[i4] && temp[1] = Strs[i4] && temp[2]! = strs[i4]&&temp[3]!=Strs[i4]) - { -temp[4] =Strs[i4]; - for(inti5 =0; i5 < STRs. Length; i5++) - { in if(temp[0] = Strs[i5] && temp[1] = Strs[i5] && temp[2] = Strs[i5] && temp[3]! = strs[i5]&&temp[4]!=Strs[i5]) - { totemp[5] =Strs[i5]; + for(intI6 =0; I6 < STRs. Length; i6++) - { the if(temp[0] = Strs[i6] && temp[1] = Strs[i6] && temp[2] = Strs[i6] && temp[3] = Strs[i6] && temp[4]! = strs[i6]&&temp[5]!=Strs[i6]) * { $temp[6] =Strs[i6];Panax Notoginseng for(inti7 =0; i7 < STRs. Length; i7++) - { the if(temp[0] = Strs[i7] && temp[1] = Strs[i7] && temp[2] = Strs[i7] && temp[3] = Strs[i7] && temp[4] = Strs[i7] && temp[5]! = strs[i7]&&temp[6]!=Strs[i7]) + { Atemp[7] =Strs[i7]; thex + +;//as a statistic of the number of poor + - } $ $ } - } - the } - }Wuyi the } - } Wu - } About } $ - } - } - A } + } the - } $ } the Console.WriteLine (x); the console.readline (); the}
The blood lesson tells us 8*7*6*5*4*3*2=40320
I tried, if each string array to output, it would take about 10 minutes. Not to mention, iterate through each string array and then match the rules and output. This is only 4 numbers, this method directly flutter street (PU gai)!
The second method. Use the same numbers directly to exclude them. Then the poor lift:
Method Example: Assuming the first method of "X1", "X2" is 1 then in the second method x1,x3,x2 only one, in the first method is counted at least two.
This method directly reduces the array to
Not much to say directly on the code
Poor lifting method two
The whole reduction for the original 1/16.
Second step: rule matching. Find an array that fits the requirements in all possible arrays
The poor is done, and then the rules match.
Iterates through an array. The value is then added 1 according to the absolute value of the index position difference of the two identical numbers in the array;
Note: Consider an issue where the index is out of bounds!
1 public static bool Isyes (string[] str) 2 {3 bool Isyon = False, 4 list<string> in TList =new list<string> (); 5 for (int i = 0; i < str. Length; i++) 6 {7 Try 8 {9 if (str[i] = = Str[i + Convert.ToInt32 ( Str[i]) + 1] | | Str[i] = = Str[i-convert.toint32 (Str[i])-1] Each {Intlist.add (str[i]); 13 Isyon = true;14}15 Else16 {17 return false;18}19}20 catch (Exception) 21 {22 2 3 if (str[i] = = Str[math.abs (I-convert.toint32 (Str[i))-1)]&&intlist.contains (Str[i]) 24 {Isyon = true;26}27 else28 {false;30 return }31}32}33 return isyon;34}
Rule Matching
Such
This article does not have a very high technical content. But also more test the coherence of ideas.
The writing is not good, the expression has the place which is not in place, also invites everybody many forgive.
I am basically ignorant of the algorithm. If there is a good method of learning the algorithm also please do not Sik Sik Yuen Enlighten. will be greatly appreciated!
If there is a better way to implement, or the improved method can be indicated in the comments below or sent to my mailbox paul_0715 at sina dot com
"Exhaustive" implements an array (1,1,2,2,3,3,4,4) arrangement in C #, which is spaced between each of the two identical numbers.