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:19:41 on Problem 1050
In Reply To:暴力的下场是超时!! Posted by:eleapple at 2005-10-10 01:03:41
#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,okmax,**s;
	scanf("%d",&n);
	s=(int**)malloc(n*sizeof(int*));
	for(i=0;i<n;i++)
		s[i]=(int*)malloc(n*sizeof(int));
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			scanf("%d",&s[i][j]);
		okmax=s[0][0];
	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;
				}
					if(max>okmax)
						okmax=max;
		}
				printf("%d\n",okmax);
	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