hdu 2830 Matrix Swapping II(額,,排序?)

來源:互聯網
上載者:User

標籤:

題意:

N*M的矩陣,每個格中不是0就是1。

可以任意交換某兩列。最後得到一個新矩陣。

問可以得到的最大的子矩形面積是多少(這個子矩形必須全是1)。

 

思路:

先統計,a[i][j]記錄從第i行第j列格往上連續的0的個數。

枚舉每一行作為答案子矩陣的底, 然後將這一行的a[i][j]從大到小排序,掃一遍計算。

看代碼。

 

代碼:

int n,m;char temps[1005][1005];int a[1005][1005]; int ts[1005];bool cmp(int a,int b){    return a>b;}int main(){    while(scanf("%d%d",&n,&m)!=EOF){        rep(i,0,n-1){            scanf("%s",temps[i]);        }        mem(a,0);        rep(i,0,m-1) if(temps[0][i]==‘0‘) a[0][i]=0; else a[0][i]=1;        rep(i,1,n-1){            rep(j,0,m-1){                if(temps[i][j]==‘1‘) a[i][j]=1+a[i-1][j];            }        }        int ans=0;        rep(i,0,n-1){            rep(j,0,m-1) ts[j]=a[i][j];            sort(ts,ts+m,cmp);            rep(i,0,m-1) ans=max( ans,ts[i]*(i+1) );        }        printf("%d\n",ans);    }    return 0;}

 

hdu 2830 Matrix Swapping II(額,,排序?)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.