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

Re:一种解法.

Posted by 20105659 at 2011-08-07 08:54:29 on Problem 1050
In Reply To:Re:又一个把自己代码拿出来炫的 Posted by:I08690127 at 2009-07-27 12:24:01
第一种算法有误,但是能过了北大OJ,不信可以试试
可以试试
3
0 0 -1
0 0 1
-1 0 2
输出结果:3
将第一种算法改为如下就对了:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
	int c,res=0,k,i,j;
	int d[100][100];
	int s[101],a[100];
	while(scanf("%d",&c)==1)
	{
		for( i=0;i<c;i++)
		{
			for( j=0;j<c;j++)
			{
				scanf("%d",&d[i][j]);
			}
		}
		for( i=0;i<c;i++)
		{
			for( j=(i+1);j<c;j++)
			{
				memset(a,0,sizeof(a));
				memset(s,0,sizeof(s));
				for(k=0;k<c;k++)
				{
					int m;
					for( m=i;m<=j;m++)
						a[k]+=d[m][k];
					if(s[k]>=0)
						s[k+1]=s[k]+a[k];
					else
						s[k+1]=a[k];
				}
				int c;
				for( c=0;c<k+1;c++)
				{
					if(res<s[c])
						res=s[c];
				}
			}
		}
		printf("%d",res);
	}
	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