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

暴力的下场是超时!!

Posted by eleapple at 2005-10-10 01:03:41 on Problem 1050
#include<stdio.h>
#include<stdlib.h>
int sumofsubrect(int **s, int r1, int c1, int r2, int c2)
{
	int sum=0,i,j;
	for(i=r1;i<=r2;i++)
		for(j=c1;j<=c2;j++)
			sum=sum+s[i][j];
		return sum;
}
int main()
{
	int i,j,n,max,r,c,temp,**s;
	int **a;
	scanf("%d",&n);
	s=(int**)malloc(n*sizeof(int*));
	a=(int**)malloc(n*sizeof(int*));
	for(i=0;i<n;i++)
	{
		s[i]=(int*)malloc(n*sizeof(int));
		a[i]=(int*)malloc(n*sizeof(int));
	}
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			scanf("%d",&s[i][j]);
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
		{
			max=s[i][j];
			for(r=0;r<=i;r++)
				for(c=0;c<=j;c++)
				{
					temp=sumofsubrect(s,r,c,i,j);
					if(temp>max)
						max=temp;
				}
					a[i][j]=max;
					
		}
		max=a[0][0];
		for(i=0;i<n;i++)
			for(j=0;j<n;j++)
				if(a[i][j]>max)
					max=a[i][j];
				printf("%d\n",max);
	return 1;
}

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