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

第一次做最大和子段,一次ac,16ms

Posted by zpdlut at 2010-08-19 11:13:44 on Problem 1050
#include<iostream>
using namespace std;
int rec[101][101];
//int m=0;
//void get(int ans[101],int nums)
//{
//	int b = 0;
//	for(int i=0;i<nums;i++)
//	{
//		if(b<0)
//			b = ans[i];
//		else
//			b +=ans[i];
//		if(b>m)
//			m = b;
//	}
//}
int main()
{
	int nums;
	int result[101];
	cin>>nums;
	int m=0;
	for(int i=0;i<nums;i++)
	{
		for(int j=0;j<nums;j++)
		{
			cin>>rec[i][j];
		}
	}
	for(int i=0;i<nums;i++)
	{
		memset(result,0,sizeof(result));
		for(int j=i;j<nums;j++)
		{			
			int b = 0;
			for(int k=0;k<=nums;k++)
			{
				result[k]+=rec[j][k];
				if(b<=0)
					b = result[k];
				else
					b +=result[k];
				if(b>m)
					m=b;
			}

		}
	}
	cout<<m<<endl;
	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