The key to this question is how you choose to calculate the bricks that need to be added, starting from the height of the child or from the big height. The main subject is a new array to store the number of bricks starting from the largest (maximum height) brick. In the Code "for (int k=m;k>=1;k--)"
Then through the following str[iii][j]= ' 1 '; To make up, and then calculate the number of bricks of the second largest height. And so on, come to a conclusion.
#include <iostream>#include<cstring>using namespacestd;Const intM = $;intMain () {intM,n; CharStr[m][m]; intPp[m]; CIN>>m>>N; GetChar (); intI,j,k,ii,c; for(i=0; i<m;i++) gets (Str[i]); for(k=m;k>=1; k--) { intCount =0; for(j=0; j<n;j++) { for(i=0; i<m;i++) { if(str[i][j]=='0') {C=0; for(ii=i;ii<m;ii++) { if(str[ii][j]=='0') C++; Else{II--; Break; } } if(c==k) {Count++; for(intiii=i;iii<=ii;iii++) Str[iii][j]='1'; } I=II; } }} pp[k-1]=count; } for(i=0; i<m;i++) if(pp[i]!=0) cout<<i+1<<" "<<pp[i]<<Endl; return 0;}
Tianda ACM 1090. City Hall