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 mediatek at 2011-10-13 18:36:19 on Problem 1050
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int n,res;
	int data[100][100];
	int s[101],a[100];
	while(scanf("%d",&n)==1)
	{
		/* input data */
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				scanf("%d",&data[i][j]);
			}
		}
		res = data[0][0];

		for(int i=0;i<n;i++)
		{
			for(int j=i;j<n;j++)
			{
				/* initial */
				for(int t=0;t<100;t++)
				{
					a[t]=0;
					s[t]=0;
				}

				for(int col=0;col<n;col++)
				{
					for(int row=i;row<=j;row++)
						a[col]+=data[row][col];
					if(s[col]>0)
						s[col+1]=a[col]+s[col];
					else
						s[col+1]=a[col];
				}

				for(int t=1;t<=n;t++)
				{
					if(res<s[t])
						res=s[t];
				}
			}
		}
		printf("%d",res);
	}
}

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