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

居然16ms

Posted by dlutwuwei at 2011-11-30 21:52:34 on Problem 1050
输入只要求一组数据,遍历所有子矩阵,不知道如何提高了。
	int N;
	int** input;
	int *arrrow, *arr;
	int i;
	scanf("%d", &N);
	//while(scanf("%d", &N),N)
	//{
		input = new int*[N];
       	for (i=0; i<N; i++)
       	{
			input[i] = new int[N];
       		for(int j=0; j<N; j++)
       		{
       			scanf("%d", &input[i][j]);
       		}
       	}
       	int max = -999999;
       	arrrow = new int[N];// sum of row
       	arr = new int[N]; // sum of sub rectangle
       	for (i=0; i<N; i++)// sub-rectangle start line
       	{   
			memset(arrrow, 0, sizeof(int)*N);
       		for (int j=i; j<N; j++)// i line to N line
       		{
				memset(arr,0, sizeof(int)*N);
       			for (int k=0; k<N; k++)// sub-rectangle row
       			{
       				arrrow[k] += input[j][k];
				
       				if ( arr[k==0?0:k-1]+arrrow[k]>arr[k==0?0:k-1])
       				{
						arr[k] = arr[k==0?0:k-1] + arrrow[k];
       
       					if (arr[k]>max)
       						max = arr[k];
       				}else{
       					arr[k]=0;
       
       					if (arr[k]>max)
       						max = arr[k];
       				}
       			}
       		}
       	}
       	printf("%d", max);
	//}
	return 0;
}

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