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:大哥,你这算法n^3的好不?

Posted by yzhw at 2009-02-13 09:59:55 on Problem 1050
In Reply To:除了代码短点,没别的优点了,感觉给我写成了n^4的算法鸟,原来用C++还超时来着…… Posted by:Web_Board at 2009-01-15 01:28:48
> #include<stdio.h>
> #include<malloc.h>
> int main()
> {
> 	int n,i,j,g,k,b2,s,ma[101][101],* b;
> 	scanf("%d",&n);
> 	for(j=1;j<=n;j++)
> 		for(i=1;i<=n;i++)
> 			scanf("%d",&ma[j][i]);
> 	b=(int *)malloc(sizeof(int)*(n+1));
> 	s=-10000;
> 	for(k=1;k<=n;k++){
> 		for(g=k;g<=n;g++){//k->g column枚举每种列的情况
> 			for(j=1;j<=n;j++){
> 				b[j]=0;
> 				for(i=k;i<=g;i++)
> 					b[j]+=ma[j][i];
> 			}	
> 			b2=0;
> 			for(j=1;j<=n;j++){//一维数组的DP步骤
> 				if(b2>0)
> 					b2+=b[j];
> 				else
> 					b2=b[j];
> 				if(b2>s)
> 					s=b2;
> 			}
> 		}
> 	}
> 	printf("%d",s);
> 	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