青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

posts - 18,  comments - 5,  trackbacks - 0
一、題目描述

Description

Dearboy, a goods victualer, now comes to a big problem, and he needs your help. In his sale area there are N shopkeepers (marked from 1 to N) which stocks goods from him.Dearboy has M supply places (marked from 1 to M), each provides K different kinds of goods (marked from 1 to K). Once shopkeepers order goods, Dearboy should arrange which supply place provide how much amount of goods to shopkeepers to cut down the total cost of transport.

It's known that the cost to transport one unit goods for different kinds from different supply places to different shopkeepers may be different. Given each supply places' storage of K kinds of goods, N shopkeepers' order of K kinds of goods and the cost to transport goods for different kinds from different supply places to different shopkeepers, you should tell how to arrange the goods supply to minimize the total cost of transport.

Input

The input consists of multiple test cases. The first line of each test case contains three integers N, M, K (0 < N, M, K < 50), which are described above. The next N lines give the shopkeepers' orders, with each line containing K integers (there integers are belong to [0, 3]), which represents the amount of goods each shopkeeper needs. The next M lines give the supply places' storage, with each line containing K integers (there integers are also belong to [0, 3]), which represents the amount of goods stored in that supply place.

Then come K integer matrices (each with the size N * M), the integer (this integer is belong to (0, 100)) at the i-th row, j-th column in the k-th matrix represents the cost to transport one unit of k-th goods from the j-th supply place to the i-th shopkeeper.

The input is terminated with three "0"s. This test case should not be processed.

Output

For each test case, if Dearboy can satisfy all the needs of all the shopkeepers, print in one line an integer, which is the minimum cost; otherwise just output "-1".

Sample Input

1 3 3
1 1 1
0 1 1
1 2 2
1 0 1
1 2 3
1 1 1
2 1 1
1 1 1
3
2
20
0 0 0

Sample Output

4
-1


二、分析
      一個(gè)的最小費(fèi)用最大流問題,詳細(xì)算法:最小費(fèi)用最大流
三、代碼

  1#include<iostream>
  2#include<queue>
  3using namespace std;
  4int n, m, kind;
  5int s, t;
  6int order[51][51];
  7int store[51][51];
  8int cost[51][51][51];
  9int c[102][102];
 10int f[102][102];
 11int b[102][102];
 12int p[102];
 13int d[102];
 14bool visit[102]; //表示spfa中點(diǎn)是否在隊(duì)列中
 15void spfa() //求Gf的最短路
 16{
 17    queue<int> q;
 18    memset(visit, 0sizeof(visit));
 19    q.push(s);
 20    visit[s] = true;
 21    while(!q.empty())
 22    {
 23        int u = q.front();
 24        visit[u] = false;
 25        q.pop();
 26        for(int v=0; v<=n+m+1; v++)
 27            if(c[u][v] > f[u][v] && d[v] > d[u] + b[u][v])
 28            {
 29                d[v] = d[u] + b[u][v];
 30                p[v] = u;
 31                if(!visit[v])
 32                {
 33                    q.push(v);
 34                    visit[v] = true;
 35                }

 36            }

 37    }

 38}

 39void mcmf()
 40{
 41    while(1)
 42    {
 43        memset(p, -1sizeof(p));
 44        for(int i=1; i<=n+m+1; i++)
 45            d[i] = 100000;
 46        d[s] = 0;
 47        spfa();
 48        if(p[t] == -1//表示已無增廣路
 49            break;
 50        int minf = INT_MAX;
 51        int it = t;
 52        while(p[it] != -1)
 53        {
 54            minf = min(minf, c[p[it]][it] - f[p[it]][it]);
 55            it = p[it];
 56        }

 57        it = t;
 58        while(p[it] != -1)
 59        {
 60            f[p[it]][it] += minf;
 61            f[it][p[it]] = -f[p[it]][it];
 62            it = p[it];
 63        }

 64    }

 65}

 66int main()
 67{
 68    while(1)
 69    {
 70        scanf("%d%d%d"&n, &m, &kind);
 71        if(n==0 && m==0 && kind==0)
 72            break;
 73        for(int i=1; i<=n; i++)
 74            for(int j=1; j<=kind; j++)
 75                scanf("%d"&order[i][j]);
 76        for(int i=1; i<=m; i++)
 77            for(int j=1; j<=kind; j++)
 78                scanf("%d"&store[i][j]);
 79        for(int i=1; i<=kind; i++)
 80            for(int j=1; j<=n; j++)
 81                for(int k=1; k<=m; k++)
 82                    scanf("%d"&cost[i][k][j]);
 83        s = 0; t = m+n+1;
 84        int res = 0;
 85        bool flag = true;
 86        for(int i=1; i<=kind; i++)
 87        {
 88            memset(c, 0sizeof(c));
 89            for(int j=1; j<=m; j++)
 90                c[s][j] = store[j][i];
 91            for(int j=1; j<=m; j++)
 92                for(int k=1; k<=n; k++)
 93                    c[j][k+m] = store[j][i];
 94            for(int j=1; j<=n; j++)
 95                c[j+m][t] = order[j][i];
 96            memset(b, 0sizeof(b));
 97            for(int j=1; j<=m; j++)
 98                for(int k=1; k<=n; k++)
 99                {
100                    b[j][k+m] = cost[i][j][k];
101                    b[k+m][j] = -b[j][k+m]; //負(fù)費(fèi)用,表示回流會(huì)減小費(fèi)用
102                }

103            memset(f, 0sizeof(f));
104            mcmf();
105            for(int j=1; j<=n; j++)
106                if(c[j+m][t] != f[j+m][t])
107                {
108                    flag = false;
109                    break;
110                }

111            if(!flag) break;
112            for(int j=1; j<=m; j++)
113                for(int k=1; k<=n; k++)
114                    res += f[j][m+k] * b[j][m+k];
115        }

116        if(flag)
117            printf("%d\n", res);
118        else
119            printf("-1\n");
120    }

121}
posted on 2009-06-30 22:09 Icyflame 閱讀(3364) 評論(1)  編輯 收藏 引用 所屬分類: 解題報(bào)告
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美午夜精品理论片a级大开眼界 欧美午夜精品理论片a级按摩 | 欧美大片18| 一本色道久久综合一区 | 午夜精品久久久久久久白皮肤 | 欧美日韩精品一区| 免费久久99精品国产| 久久久综合网站| 欧美主播一区二区三区美女 久久精品人 | 国产在线不卡精品| 国产一区二区三区久久| 西西裸体人体做爰大胆久久久| 久久精品国产综合| 久久亚洲欧美| 久久精品国产第一区二区三区| 国产精品免费看片| 亚洲美女一区| 91久久黄色| 国产精品久久久久久久7电影| 久久久国产成人精品| 久久久国际精品| 亚洲一区二区三区四区五区黄| 这里只有精品在线播放| 亚洲久久成人| 欧美一级在线播放| 久久成人一区二区| 久久国产精品网站| 欧美精品久久久久久久免费观看 | 久久精品网址| 欧美激情综合在线| 欧美日本国产精品| 国际精品欧美精品| 亚洲欧洲一区| 亚洲女女女同性video| 亚洲国产日韩欧美在线图片| 中国成人黄色视屏| 欧美影院在线播放| 亚洲视频1区2区| 欧美午夜精品一区二区三区| 亚洲乱码国产乱码精品精| 亚洲高清久久网| 久久久一区二区| 亚洲成人资源| 亚洲欧洲在线一区| 欧美搞黄网站| 亚洲一区在线观看免费观看电影高清 | 一区二区三区黄色| 91久久在线| 欧美在线观看视频一区二区三区| 久久精品首页| 亚洲麻豆国产自偷在线| 久久美女艺术照精彩视频福利播放| 欧美黄色网络| 久久亚洲国产精品日日av夜夜| 亚洲精品在线视频观看| 国产亚洲精品久久久| 亚洲一区二区三区精品动漫| 欧美国产一区二区在线观看| 欧美一区二区三区视频免费播放| 六月天综合网| 亚洲黄色在线| 乱人伦精品视频在线观看| 国产精品久久久久久久久免费桃花| 国产偷国产偷亚洲高清97cao | 久久精品国产欧美亚洲人人爽| 欧美激情亚洲国产| 黑人操亚洲美女惩罚| 久久精品视频免费观看| 妖精视频成人观看www| 亚洲色诱最新| 国产精品久久久久久影视| 亚洲激情在线播放| 中文精品一区二区三区 | 精久久久久久| 亚洲欧美日韩另类精品一区二区三区| 久久综合伊人| 久久野战av| 狠狠干综合网| 亚洲精品国产拍免费91在线| 欧美国产欧美综合 | 久久久久久久久久看片| 韩国一区二区三区在线观看| 久久精品电影| 久久久久综合网| 韩日在线一区| 久久综合亚州| 欧美乱妇高清无乱码| 亚洲国产一区二区三区青草影视 | 欧美精品日韩综合在线| 精品福利免费观看| 免费在线看成人av| 久久美女性网| 亚洲少妇诱惑| 国产亚洲人成a一在线v站| 亚洲精品韩国| 久热精品视频在线| 亚洲开发第一视频在线播放| 欧美一区二区三区视频在线| 欧美日本亚洲韩国国产| 一区二区三区色| 这里只有精品电影| 国产精品中文在线| 欧美gay视频| 欧美精品一区二区三区视频| 亚洲视频一区在线观看| 久久久久青草大香线综合精品| 老鸭窝亚洲一区二区三区| 亚洲第一免费播放区| 久久黄金**| 国内视频一区| 亚洲综合精品自拍| 麻豆精品一区二区av白丝在线| 亚洲精品一区二区三区99| 亚洲精品一区二区三区福利| 国产视频欧美视频| 欧美成人精品高清在线播放| 欧美久久在线| 欧美不卡视频一区| 欧美日韩视频专区在线播放| 麻豆精品在线播放| 欧美日韩天堂| 久久嫩草精品久久久久| 亚洲一区二区欧美| 久久久精品动漫| 午夜精彩视频在线观看不卡| 欧美在线日韩| 一本色道88久久加勒比精品 | 久久久精品性| 欧美精品粉嫩高潮一区二区| 久久人人97超碰精品888| 欧美成人午夜激情| 久久激情五月丁香伊人| 国产精品区一区二区三| 欧美风情在线| 国产亚洲精品一区二区| 99在线|亚洲一区二区| 亚洲国产成人在线视频| 亚洲高清激情| 精品动漫av| 欧美一二三区精品| 久久成人羞羞网站| 欧美日韩一区二区三区在线视频 | 欧美成人精品| 亚洲大片免费看| 欧美一级久久| 久久久综合免费视频| 国产精品手机视频| 亚洲视频www| 在线视频精品一区| 欧美激情一区二区三区在线| 欧美国产日本| 国产精品露脸自拍| 久久综合久久久| 狠狠狠色丁香婷婷综合久久五月| 中文一区二区在线观看| 午夜国产精品影院在线观看| 欧美午夜视频网站| 久久九九精品| 欧美精品入口| 亚洲电影有码| 亚洲一级黄色片| 欧美日韩亚洲激情| 国产欧美日韩视频一区二区三区| 欧美一区二区三区在线视频| 欧美激情bt| 久久久青草婷婷精品综合日韩| 欧美二区在线| 久久影音先锋| 亚洲欧美日韩国产综合| 一区二区三区四区五区在线| 99视频精品在线| 亚洲午夜免费视频| 欧美亚洲日本国产| 激情综合色丁香一区二区| 久久成人免费日本黄色| 亚洲午夜激情免费视频| 国产一区二区高清不卡| 久久精品国产v日韩v亚洲| 亚洲国产精品久久久久婷婷884 | 欧美3dxxxxhd| 亚洲精品一二三| 欧美一区二区三区免费在线看| 国产综合香蕉五月婷在线| 男女激情视频一区| 亚洲美洲欧洲综合国产一区| 一区二区国产精品| 香蕉尹人综合在线观看| 毛片一区二区三区| 99精品视频免费全部在线| 国产精品久久久久影院亚瑟| 欧美一区二区免费| 欧美在线观看网址综合| 红桃视频国产一区| 欧美精品成人91久久久久久久| 久久免费午夜影院| 在线视频你懂得一区| 国内偷自视频区视频综合| 国产精品ⅴa在线观看h| 噜噜噜噜噜久久久久久91| 欧美激情视频免费观看| 老牛嫩草一区二区三区日本|