Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static public void Problem24()
- {
- //A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4.If all of the permutations are listed numerically or alphabetically, we call it lexicographic order.The lexicographic permutations of 0, 1 and 2 are:
- //012 021 102 120 201 210
- //What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9 ?
- bool[] isUsed = new bool[10];
- int[] permutation = new int[10];
- StringBuilder sb = new StringBuilder();
- //(╥_╥)
- int count = 0;
- for (int a = 0; a < 10; a++)
- {
- isUsed[a] = true;
- for (int b = 0; b < 10; b++)
- {
- if (isUsed[b])
- {
- continue;
- }
- else
- {
- isUsed[b] = true;
- for (int c = 0; c < 10; c++)
- {
- if (isUsed[c])
- {
- continue;
- }
- else
- {
- isUsed[c] = true;
- for (int d = 0; d < 10; d++)
- {
- if (isUsed[d])
- {
- continue;
- }
- else
- {
- isUsed[d] = true;
- for (int e = 0; e < 10; e++)
- {
- if (isUsed[e])
- {
- continue;
- }
- else
- {
- isUsed[e] = true;
- for (int f = 0; f < 10; f++)
- {
- if (isUsed[f])
- {
- continue;
- }
- else
- {
- isUsed[f] = true;
- for (int g = 0; g < 10; g++)
- {
- if (isUsed[g])
- {
- continue;
- }
- else
- {
- isUsed[g] = true;
- for (int h = 0; h < 10; h++)
- {
- if (isUsed[h])
- {
- continue;
- }
- else
- {
- isUsed[h] = true;
- for (int i = 0; i < 10; i++)
- {
- if (isUsed[i])
- {
- continue;
- }
- else
- {
- isUsed[i] = true;
- for (int j = 0; j < 10; j++)
- {
- if (isUsed[j])
- {
- continue;
- }
- else
- {
- count++;
- isUsed[j] = true;
- sb.Clear();
- if (count == 1000000)
- {
- permutation[0] = a;
- permutation[1] = b;
- permutation[2] = c;
- permutation[3] = d;
- permutation[4] = e;
- permutation[5] = f;
- permutation[6] = g;
- permutation[7] = h;
- permutation[8] = i;
- permutation[9] = j;
- for (int r = 0; r < 10; r++)
- {
- sb.Append(permutation[r]);
- }
- Console.Write(sb + "");
- goto end;
- }
- }
- isUsed[j] = false;
- }
- }
- isUsed[i] = false;
- }
- }
- isUsed[h] = false;
- }
- }
- isUsed[g] = false;
- }
- }
- isUsed[f] = false;
- }
- }
- isUsed[e] = false;
- }
- }
- isUsed[d] = false;
- }
- }
- isUsed[c] = false;
- }
- }
- isUsed[b] = false;
- }
- isUsed[a] = false;
- }
- end:;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement