My idea:
At first I solve this problem with the greedy approach (keeping the number maximal for every iteration) and all the test cases given is right . Later on I find some cases from the discussion that my code gives the wrong answer .
For example : 35766 3
the correct result is that 35766->75366->76356->76653
but the greedy approach works like this : 35766->75366->76365->76635
Here I will use the make permutation and memory search to solve this problem , and I have learn much about STL in C++ this time .
Problem Statement | |||||||||||||
There is nothing more beautiful than just an integer number. You are given an integer n. Write down n in decimal notation with no leading zeroes, and let M be the number of written digits. Perform the following operation exactly k times:
Return the maximal possible number you can get at the end of this procedure. If it's not possible to perform k operations, return -1 instead. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
- | n will be between 1 and 1,000,000, inclusive. | ||||||||||||
- | k will be between 1 and 10, inclusive.
|