• hdu2853


                                  Assignment

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 659    Accepted Submission(s): 342


    Problem Description
    Last year a terrible earthquake attacked Sichuan province. About 300,000 PLA soldiers attended the rescue, also ALPCs. Our mission is to solve difficulty problems to optimization the assignment of troops. The assignment is measure by efficiency, which is an integer, and the larger the better.
    We have N companies of troops and M missions, M>=N. One company can get only one mission. One mission can be assigned to only one company. If company i takes mission j, we can get efficiency Eij. 
    We have a assignment plan already, and now we want to change some companies’ missions to make the total efficiency larger. And also we want to change as less companies as possible.
     
    Input
    For each test case, the first line contains two numbers N and M. N lines follow. Each contains M integers, representing Eij. The next line contains N integers. The first one represents the mission number that company 1 takes, and so on.
    1<=N<=M<=50, 1<Eij<=10000.
    Your program should process to the end of file.
     
    Output
    For each the case print two integers X and Y. X represents the number of companies whose mission had been changed. Y represents the maximum total efficiency can be increased after changing.
     
    Sample Input
    3 3
    2 1 3
    3 2 4
    1 26 2
    2 1 3
    2 3
    1 2 3
    1 2 3
    1 2
     
    Sample Output
    2 26
    1 2
    #include<iostream>
    using namespace std;
    const int inf = 1000000;
    const int maxn = 305;
    int vx[maxn],vy[maxn],g[maxn][maxn],weight[maxn],n,m,linky[maxn],lx[maxn],ly[maxn],ans;
    int dfs(int x)
    {
        int y;
        vx[x] = true;
        for(y=1;y<=m;y++)
        {
            if(!vy[y] && lx[x] + ly[y]==g[x][y])
            {
                vy[y] =true;
                if(linky[y]==-1 || dfs(linky[y]))
                {
                    linky[y] = x; return 1;
                }
            }
            else
            {
                if(weight[y] > lx[x]+ly[y] - g[x][y])
                {
                    weight[y] = lx[x] + ly[y] - g[x][y];
                }
            }
        }
        return 0;
    
    }
    int KM()
    {
        int i,j,lack,x;
        memset(linky,-1,sizeof(linky));
        memset(ly,0,sizeof(ly));
        for(i=1;i<=n;i++)
        {
            lx[i] = -inf;
            for(j=1;j<=m;j++)
            {
                if(g[i][j] > lx[i])
                    lx[i] = g[i][j];
            }
        }
        for(x=1;x<=n;x++)
        {
            for(j=1;j<=m;j++)
            {
                weight[j] = inf;
            }
            while(1)
            {
                memset(vx,0,sizeof(vx));
                memset(vy,0,sizeof(vy));
                if(dfs(x)) break;
                lack = inf;
                for(i=1;i<=n;i++)
                {
                    if(vx[i])
                    {
                        for(j=1;j<=m;j++)
                        {
                            if(!vy[j] && lack > lx[i] + ly[j] - g[i][j])
                            {
                                lack = lx[i] + ly[j] - g[i][j];
                            }
                        }
                    }
                }
                for(i=1;i<=n;i++)
                {
                    if(vx[i])
                        lx[i] -= lack;
                }
                for(j=1;j<=m;j++)
                {
                    if(vy[j])
                        ly[j] += lack;
                }
            }
        }
        ans = 0;
        for(i=1;i<=m;i++)
        {
            if(linky[i]!=-1)
            {
                ans += g[linky[i]][i];
            }
        }
        return ans;
    }
    int main()
    {
    //    int n,m;
        while(scanf("%d %d",&n,&m)!=EOF)
        {
            int i,j,tt,sum=0;
            for(i=1;i<=n;i++)
            {
                for(j=1;j<=m;j++)
                {
                    scanf("%d",&g[i][j]);
                    g[i][j]*=100;
                }
            }
            for(i=1;i<=n;i++)
            {
                scanf("%d",&tt);
                g[i][tt]++;
                sum += g[i][tt];
            }
            KM();
             printf("%d %d
    ",sum%100-ans%100,ans/100-sum/100);  
        }
        return 0;
    }
  • 相关阅读:
    用户场景分析
    团队项目个人工作总结(4月22日)
    团队项目个人工作总结(4月21日)
    团队项目个人工作总结(4月20日)
    第九周学习进度情况
    站立会议10-个人总结
    站立会议9-个人总结
    站立会议8-个人总结
    textarea中文提交乱码问题解决
    站立会议7-个人总结
  • 原文地址:https://www.cnblogs.com/Deng1185246160/p/3242349.html
Copyright © 2020-2023  润新知