The most-valued problem in delete
(1) The minimum number after the integer is deleted: please delete 9 numbers in integer n = 83179254297017652, so that the remaining numbers make up the smallest new number in the original order.
Design essentials: After removing s digits in the integer n, the remaining digits form a new positive integer m to the given n,s to find a scheme that makes up the smallest number, the manipulation data can be high-precision data, where the string input method is used, each time a number is deleted, and the remaining number is selected, The smallest number as the deletion object chooses such greedy operation because the removal of the S number global optimal solution contains the optimal solution to delete a number sub-problem.
when s = 1 O'Clock does removing that number in n achieve the smallest possible purpose? from left to right each adjacent two numbers, if the left is greater than the right to delete the left large number, if not all the numbers are all the same or ascending, delete the right number. when the s>1 (also less than N) in accordance with the above operation one of the deletion, delete A to reach the minimum, and then from the beginning of the string to delete the 2nd one by one number, in turn, decomposition for s operations completed. If the deletion of less than S will appear without the left number is greater than the number on the right, stop the operation, print the left of the remaining string of n.length-s digital Java code implementation:
PackageDemo1;ImportJava.util.Scanner; Public classMain {/*** Maximum value problem in Delete *@paramargs*/ Public Static voidMain (string[] args) {Scanner input=NewScanner (system.in); String Str=Input.next (); Char[]C =Str.tochararray (); ints =Input.nextint (); System.out.println ("Enter the element that has been deleted:"); intx = 0; intT=0; intI=0; while(s>x&&t==0) { //the first character that decrements the deletion appears if(C[i] > c[i+1]) {System.out.print (C[i]+" " ); for(intK = i;k<=c.length-2-x;k++) //removes a number that follows a number forwardC[k] = c[k+1]; X++;//x counts the number of deleted numbersi =-1;//find the descending interval from the beginning } //if there is no decreasing interval t==1 if(i = = C.length-x-2) {T= 1; } I++; } System.out.println (); //The minimum number of prints to get for(intj=0;j<=c.length-1-s;j++) {System.out.print (C[j]+" "); } }}
Operation Result:
83179254297017652
9
Enter the elements that have been deleted successively:
8 3 9 7 5 4 9 7 2
1 2 0 1 7 6 5 2
Optimal decision-making problem