| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:哎,出发地是城市1,我又忘了处理了。应该这样子: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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator