[Description]
Humans finally landed on the land of Mars and saw the mysterious Martian. Neither human nor Martian can understand each other's language, but our scientists have invented a method of digital communication. This communication method is like this. First, the Martian tells a very large number to a human scientist. After scientists crack the meaning of this number, they add a small number to this large number, tell the result to the Martian as a human answer.
The Martian represents numbers in a very simple way-finger-breaking. The Martian has only one hand, but there are thousands of fingers in the hand. These fingers are arranged in a column numbered 1, 2, 3 ....... Any two fingers of the Martian can exchange positions at will, and they count by this method.
A Martian uses a human hand to demonstrate how to count with fingers. If the five fingers-thumb, forefinger, middle finger, ring finger, and small finger are numbered 1, 2, 3, 4, and 5, they are arranged in the normal order, forming a 5-digit 12345, when you change the positions of the ring finger and the small finger, it will form a 5-digit 12354. When you completely reverse the order of the five fingers, it will form 54321, of all the 120 5 digits that can be formed, the minimum value is 12345, which indicates 1; the second smallest value is 12354, which indicates 2; the maximum value is 54321, which indicates 120. The following table shows the six three digits that can be formed with only three fingers and the numbers they represent:
Tridecimal number 123 132 213 231 312 321
Number 1 2 3 4 5 6
Now you have the honor to be the first person on earth to communicate with Mars. A Martian will show you his fingers, and scientists will tell you a small number to add. Your task is to add the number represented by the Martian finger to the number that the scientist tells you, and change the order of the Martian fingers according to the result. Input data to ensure that the result is not beyond the range indicated by the Martian finger.
[Input format]
The input includes three rows. The first row has a positive integer N, indicating the number of Martian fingers (1 <= n <= 10000 ). The second row is a positive integer m, indicating the small INTEGER (1 <= m <= 100) to be added ). The next line is an arrangement of the N integers from 1 to n, separated by spaces, indicating the order of the Martian fingers.
[Output format]
The output contains only one row. This row contains N integers, indicating the order of the changed Martian fingers. Separate two adjacent numbers with one space. No extra space is allowed.
[Example input]
5
3
1 2 3 4 5
[Sample output]
1 2 4 5 3
[Analysis]
Use the structure arrangement method. Similar to the jam notation.
# Include <stdio. h> # define maxn 10010int A [maxn], ANS [maxn]; int n, m, have, Count, Suc; bool V [maxn]; void make (int x) {If (x> N) {have = 1; ++ count; If (count> m) suc = 1 ;}else {for (INT I = 1; I <= N; ++ I) {If (! Have) I = A [X]; If (V [I]) continue; V [I] = 1; ans [x] = I; make (x + 1 ); V [I] = 0; If (Suc) return ;}} int main () {scanf ("% d", & N, & M ); for (INT I = 1; I <= N; ++ I) scanf ("% d", & A [I]); Make (1 ); for (INT I = 1; I <= N; ++ I) printf ("% d", ANS [I]); Return 0 ;}