上交oj 1002 二哥的花生 (待解決)

來源:互聯網
上載者:User

這到底沒做出來。。。。第一次以為窮舉就可以,結果完蛋了,逾時,又想出來了一個巧方法,結果總是wa。。。無語

http://acm.sjtu.edu.cn/OnlineJudge/problem/1002

貼出代碼來看看,以後解決

#include <iostream>using namespace std;int a[1010][1010];int sum[1010][1010];int main(){int L,W;cin>>L>>W;for(int i=0;i<L;i++)for(int j=0;j<W;j++)cin>>a[i][j];int l,w,m=0;cin>>l>>w;sum[0][0]=0;for(int i=0;i<L-l+1;i++)for(int j=0;j<W-w+1;j++){if(i==0&&j==0){for(int x=i;x-i<l;x++)for(int y=j;y-j<w;y++)sum[i][j]+=a[x][y];if(m<sum[i][j]) m=sum[i][j];}else if(j==0){sum[i][j]=sum[i-1][j];for(int y=0;y<l;y++){sum[i][j]-=a[i-1][y];sum[i][j]+=a[i+l-1][y];}if(m<sum[i][j]) m=sum[i][j];}else {sum[i][j]=sum[i][j-1];for(int x=i;x<i+w;x++){sum[i][j]-=a[x][j-1];sum[i][j]+=a[x][j+w-1];}if(m<sum[i][j]) m=sum[i][j];}}/*for(int i=0;i<L;i++){for(int j=0;j<W;j++)cout<<sum[i][j]<<" ";cout<<endl;}*/cout<<m<<endl;return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.