| ||||||||||
| 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 | |||||||||
因为忘记考虑钱可能会负的所以找了很久的错。。。#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int MAXN=105;
const int INF=-9999999;
int cost[MAXN][MAXN], get[MAXN][MAXN], dp[MAXN][MAXN];
int main()
{
int n, m, i, j, k, sum;
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==0&&m==0) break;
for(i=1; i<=n; i++)
for(j=1; j<=n; j++)
scanf("%d",&cost[i][j]);
for(j=1; j<=m; j++)
for(i=1; i<=n; i++)
scanf("%d",&get[i][j]);
for(i=0; i<=m; i++)
{
for(j=1; j<=n; j++)
{
dp[i][j]=INF;
}
}
for(i=1; i<=m; i++)
{
for(j=1; j<=n; j++)
{
for(k=1; k<=n; k++)
{
dp[i][k]=max(dp[i-1][j]-cost[j][k]+get[k][i],dp[i][k]);
}
if(i==0) break;
}
}
sum=0;
for(i=1; i<=n; i++)
if(sum<dp[m][i]) sum=dp[m][i];
printf("%d\n",sum);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator