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 Ink213 at 2013-04-17 23:00:56 on Problem 3230
#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:
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