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

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


二、分析
      一個的最小費用最大流問題,詳細算法:最小費用最大流
三、代碼

  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中點是否在隊列中
 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]; //負費用,表示回流會減小費用
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 閱讀(3363) 評論(1)  編輯 收藏 引用 所屬分類: 解題報告
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            在线一区视频| 亚洲青涩在线| 欧美一级片在线播放| 国产精品高清在线| 性18欧美另类| 久久9热精品视频| 国产日韩一区二区三区| 欧美自拍丝袜亚洲| 久久久久久亚洲精品中文字幕| 精品av久久久久电影| 久久中文字幕导航| 欧美h视频在线| 亚洲性av在线| 欧美在线亚洲一区| 亚洲欧洲精品天堂一级| 亚洲最新合集| 国内精品久久久久伊人av| 欧美好骚综合网| 欧美日韩一区二区视频在线观看| 亚洲欧美日本另类| 久久精品亚洲一区二区三区浴池| 亚洲精品一区二区三区樱花| 夜夜嗨av一区二区三区中文字幕 | 欧美成人黄色小视频| 蜜桃av一区二区| 午夜精品福利视频| 久久久久欧美| 亚洲一区二区精品在线| 久久久久国产精品麻豆ai换脸| 91久久久久久| 欧美一区二区精品久久911| 亚洲欧洲一区二区三区在线观看| 中文一区二区| 亚洲激情专区| 欧美夜福利tv在线| 一区二区三区国产盗摄| 欧美影院成年免费版| 这里只有精品视频在线| 久久久久久午夜| 午夜精品久久久| 欧美绝品在线观看成人午夜影视| 久久国产一区二区三区| 欧美日韩国产影院| 媚黑女一区二区| 国产日韩欧美视频在线| a91a精品视频在线观看| 亚洲日本欧美在线| 久久人人97超碰国产公开结果| 亚欧成人在线| 国产精品qvod| 日韩视频第一页| 亚洲精品一区二区三区婷婷月| 久久久久国产精品人| 欧美亚洲综合久久| 国产精品久久国产愉拍 | 亚洲在线观看视频网站| 欧美激情a∨在线视频播放| 男人的天堂亚洲在线| 国内精品**久久毛片app| 亚洲欧美日产图| 亚洲综合色噜噜狠狠| 欧美日韩亚洲国产一区| 亚洲免费高清| 久久一综合视频| 亚洲视屏一区| 国产精品欧美久久久久无广告| 亚洲在线免费| 欧美日产一区二区三区在线观看| 久久精品国产99国产精品| 欧美日韩一卡| 一区二区三区蜜桃网| 亚洲深夜福利视频| 欧美深夜影院| 亚洲一区成人| 久久久久久久91| 黄色成人小视频| 久久久精品国产免大香伊| 久久综合网色—综合色88| 激情丁香综合| 欧美高清在线一区| 亚洲人成网站777色婷婷| 一本色道精品久久一区二区三区 | 欧美精品激情| 亚洲人成人一区二区在线观看| 亚洲精品国精品久久99热| 免费欧美在线| 亚洲精品影院在线观看| 亚洲欧美日韩国产综合在线 | 午夜精品美女自拍福到在线| 亚洲欧美日韩中文在线制服| 国产日产亚洲精品| 噜噜噜91成人网| 99国产精品久久久久老师| 欧美一进一出视频| 亚洲第一精品久久忘忧草社区| 欧美成ee人免费视频| 日韩网站在线| 久久久最新网址| 日韩亚洲欧美高清| 国产女主播一区二区| 久久亚洲精品网站| 在线视频一区二区| 毛片基地黄久久久久久天堂| 9人人澡人人爽人人精品| 国产精品综合不卡av| 男人插女人欧美| 亚洲欧美日韩国产中文在线| 欧美韩日高清| 久久久久久噜噜噜久久久精品| 亚洲蜜桃精久久久久久久| 国产伦理一区| 欧美日韩精品二区第二页| 久久精品九九| aaa亚洲精品一二三区| 免费短视频成人日韩| 亚洲欧美日韩国产中文在线| 亚洲欧洲在线免费| 国产一区二区你懂的| 欧美新色视频| 欧美精品一区视频| 久久综合给合久久狠狠狠97色69| 亚洲一级黄色av| 日韩一级精品视频在线观看| 免费日韩成人| 久久人人看视频| 性8sex亚洲区入口| 亚洲女爱视频在线| 亚洲视频综合| 一区二区电影免费观看| 亚洲电影免费| 影音先锋国产精品| 黄色成人免费网站| 国模私拍一区二区三区| 国产日本欧美一区二区| 欧美日韩亚洲一区二区三区在线观看| 久久精品视频在线| 久久99在线观看| 欧美一区二区三区四区高清| 亚洲午夜视频在线观看| 一本色道久久综合亚洲精品高清| 亚洲日本黄色| 亚洲美女av电影| 91久久久在线| 日韩午夜av电影| 亚洲日本欧美| 99精品国产在热久久| 亚洲精品美女久久久久| 亚洲精品一区二区三区99| 亚洲欧洲日韩在线| 亚洲精品视频在线看| 亚洲伦理中文字幕| 一卡二卡3卡四卡高清精品视频| 99精品视频一区二区三区| 亚洲精品视频在线观看免费| 亚洲精品欧美日韩| 一本大道久久a久久精品综合| 亚洲麻豆国产自偷在线| 99精品国产热久久91蜜凸| 亚洲一区二区高清| 欧美在线视频网站| 久久一区二区三区国产精品| 美女视频黄免费的久久| 欧美日韩成人在线视频| 国产精品av免费在线观看| 国产精品性做久久久久久| 狠狠久久亚洲欧美专区| 亚洲精品黄网在线观看| 亚洲一区在线观看视频 | 一区二区三区高清不卡| 性娇小13――14欧美| 狂野欧美激情性xxxx| 91久久久在线| 亚洲欧美一区二区三区极速播放 | 91久久国产精品91久久性色| 一区二区日韩精品| 久久国产直播| 欧美日韩国产小视频在线观看| 国产精品实拍| 亚洲经典三级| 性色av香蕉一区二区| 欧美激情小视频| 亚洲在线播放| 欧美激情综合色综合啪啪| 国产美女精品| 99视频精品在线| 久久综合九色欧美综合狠狠| 日韩视频永久免费| 老司机成人网| 国产日韩视频| 亚洲线精品一区二区三区八戒| 久久久夜夜夜| 亚洲一区在线看| 欧美激情bt| 一色屋精品视频免费看| 亚洲视频导航| 欧美成人免费在线视频| 欧美一级淫片播放口| 欧美午夜不卡影院在线观看完整版免费| 在线不卡视频| 久久国产一区|