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:哎,出发地是城市1,我又忘了处理了。应该这样子:

Posted by 123454321 at 2007-07-29 13:06:32 on Problem 3230
In Reply To:牛牛们帮我看看这么对的代码究竟错哪儿了: Posted by:123454321 at 2007-07-20 17:13:27
/*
为什么我的输出不正确呢?
ans[i][j]  表示第i天在第j个城市
b[i][j]    表示第i天在第j个城市的收入
a[i][j]    表示从i到j的费用

ans[i][j] = max{ ans[i-1][k] + b[i][j] - a[k][j] }

此例中,ans[][]=
1 3 2 
5 3 4 
6 8 5 
*/

#include <iostream>
#include <stdio.h>
using namespace std;

int a[105][105],b[105][105],ans[105][105];
int n,m;

int main()
{
	register int i,j,k;
	int max,tem;//n city, m days
	while(scanf("%d%d",&n,&m)&&(n||m))
	{
		for(i=1;i<=n;i++)
			for(j=1;j<=n;j++)
				scanf("%d",&a[i][j]);//cost

		for(i=1;i<=m;i++)
			for(j=1;j<=n;j++)
				scanf("%d",&b[i][j]);//income

		for(i=0;i<=m;i++)
			for(j=0;j<=n;j++)
				ans[i][j]=0;

		for(j=1;j<=n;j++)
			ans[1][j]=ans[0][1] + b[1][j] - a[1][j];

		for(i=2;i<=m;i++)
			for(j=1;j<=n;j++)
			{
				max=-10000;
				for(k=1;k<=n;k++)
				{
					tem=ans[i-1][k] + b[i][j] - a[k][j];
					if(max<tem)
						max=tem;
				}
				ans[i][j]=max;
			}
		max=-10000000;
		for(i=1;i<=n;i++)
		{
			if(ans[m][i]>max)
				max=ans[m][i];
		}
		cout<<max<<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