Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

随手写了个n^4的循环40MS就过了,太水(附代码)

Posted by 986677841 at 2016-07-17 11:10:55 on Problem 1050
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator