Analysis:
1, greedy, the array to scan, if a[i]>a[i+1] to delete the a[i], until the removal of m; if the number of deleted after the scan is not enough m, then the number of the end of the list is deleted until the total deletion of M, the remaining number of the array is the result from start to finish.
2, RMQ algorithm to solve, assuming that the length of the array is Len, the number of numbers to delete is M, then the final array will be left len-m, so you can find the first in the array to m+1 the smallest number as the final result of the first position, and assume that the minimum number is labeled I, and then find the i+1 to the first m+ The minimum number of 2 as the final result of the second, subscript for J, and then from the first j+1 to M+3 to find a third, and so on, find out.
#include <iostream>using namespace Std;int dp[1010][33];char num[1010];char res[1010];void getrmq (int n) // Note that the DP array holds subscript {int i,j;for (i=0;i<=n;i++) dp[i][0]=i;for (j=1; (1<<j) <=n;j++) for (i=0;i+ (1<<J)-1 <n;i++) dp[i][j]=num[dp[i][j-1]]<=num[dp[i+ (1<< (j-1))][j-1]]?dp[i][j-1]:d p[i+ (1<< (j-1))][j-1] ;} int Query (int l,int r) {int K=0;while (1<< (k+1) <=r-l+1) K++;return num[dp[l][k]]<=num[dp[r-(1<<k) +1] [K]]? Dp[l][k]:d p[r-(1<<k) +1][k];} int main () {int m,pos,k,i;while (scanf ("%s%d", num,&m) ==2) {pos=0;k=0;i=0; GETRMQ (strlen (num)), while (M+i<strlen (num)) {pos=query (pos,m+i); res[k++]=num[pos++];i++;} for (i=0;i<k;i++) if (res[i]!= ' 0 ') break;if (i==k) Putchar (' 0 '); else{for (; i<k;i++) Putchar (Res[i]);} Putchar (' \ n ');} return 0;}
HDU ACM 3183 a Magic lamp->rmq st algorithm or greedy