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 zxlsky1314 at 2008-12-14 01:11:11 on Problem 3230
#include<stdio.h>
main(){
	int pay[100][100];
	int get[100][100];
	int a[100][100];
	int n,m,i,j,cur,k,max;
	scanf("%d %d",&n,&m);
	while(n!=0&&m!=0)
	{
		for(i=1;i<=n;i++){
			for(j=1;j<=n;j++){
			scanf("%d ",&pay[i][j]);
			}
		}
		for(i=1;i<=m;i++){
			for(j=1;j<=m;j++){
				scanf("%d ",&get[i][j]);
			}
		}
		for(j=1;j<=n;j++)
			a[1][j]=get[1][j]-pay[1][j];
		for(i=2;i<=m;i++)
		{
			for(j=1;j<=n;j++)
			{
				a[i][j]=0;
				for(k=1;k<=n;k++)
				{
					cur=a[i-1][k]+get[i][j]-pay[k][j];
					if(a[i][j]<cur)
						a[i][j]=cur;						
				}
			}
		}
		max=a[m][1];
		for(i=1;i<=n;i++)
		{
			if(a[m][i]>max)
				max=a[m][i];
		}
		printf("%d",max);
		scanf("%d %d",&n,&m);
	}
	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