Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
随手写了个n^4的循环40MS就过了,太水(附代码)#include<iostream> #include<cstdio> #include<cstdlib> #include<algorithm> using namespace std; int n; int G[101][101]; int s[101][101]; int maxn=0; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { scanf("%d",&G[i][j]); s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+G[i][j]; } for(int t=1;t<=n;t++) for(int k=1;k<=n;k++) for(int i=k;i<=n;i++) for(int j=t;j<=n;j++) { int tmp=s[i][j]-s[i-k][j]-s[i][j-t]+s[i-k][j-t]; if(tmp>maxn)maxn=tmp; } cout<<maxn<<endl; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator