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

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>
            欧美国产大片| 久久久精彩视频| 久久丁香综合五月国产三级网站| 亚洲视频在线观看网站| 亚洲美女视频在线观看| 欧美极品一区| 亚洲男女自偷自拍| 午夜一级久久| 欲香欲色天天天综合和网| 欧美电影专区| 欧美丝袜一区二区三区| 久久国产精品电影| 老司机久久99久久精品播放免费| 激情久久综合| 亚洲高清久久| 国产精品va在线| 久久偷窥视频| 欧美三级在线播放| 亚洲女爱视频在线| 久久精品亚洲一区二区三区浴池| 国产手机视频精品| 亚洲二区在线观看| 欧美国产日韩一二三区| 亚洲已满18点击进入久久| 久久精品青青大伊人av| 伊人久久大香线蕉av超碰演员| 免费成人av| 国产精品久久久久久久久久ktv| 午夜在线一区二区| 美女爽到呻吟久久久久| 亚洲欧美国产视频| 蜜臀av一级做a爰片久久| 亚洲嫩草精品久久| 免费欧美在线视频| 欧美一区二区三区在线| 欧美mv日韩mv国产网站app| 亚洲影院高清在线| 免费日本视频一区| 久久精品国产亚洲一区二区| 久久久久久亚洲综合影院红桃| 亚洲午夜小视频| 欧美日韩精品一区视频| 亚洲精品欧美极品| 99精品视频网| 亚洲大片一区二区三区| 牛人盗摄一区二区三区视频| 国产在线观看91精品一区| 日韩一级免费| 一本久道久久综合中文字幕| 美女黄毛**国产精品啪啪| 蜜桃av一区二区| 在线观看中文字幕亚洲| 久久综合九色欧美综合狠狠| 美女脱光内衣内裤视频久久网站| 国产精品五月天| 亚洲综合色视频| 久久精品在线观看| 韩国成人福利片在线播放| 久久精品二区亚洲w码| 久久久久天天天天| 亚洲大片免费看| 欧美国产日韩一区| 一本色道久久综合狠狠躁篇怎么玩| 9l国产精品久久久久麻豆| 欧美日韩三级| 亚洲欧美成人一区二区三区| 久久久久五月天| 亚洲黄色成人网| 欧美日韩情趣电影| 香蕉久久久久久久av网站| 快射av在线播放一区| 亚洲精品国产系列| 国产精品九九久久久久久久| 亚洲伊人色欲综合网| 久久中文在线| av成人动漫| 国产一区二区| 欧美高清视频一区二区| 亚洲午夜激情| 欧美国产第二页| 亚洲先锋成人| 狠狠色综合色区| 欧美日韩一区二区三区在线观看免| 中国成人在线视频| 乱人伦精品视频在线观看| 99人久久精品视频最新地址| 国产精品欧美日韩一区| 久久午夜电影网| 在线视频中文亚洲| 欧美成人激情在线| 午夜在线播放视频欧美| 亚洲国内自拍| 国产日韩欧美在线| 欧美日韩精品一本二本三本| 欧美专区亚洲专区| 99成人在线| 免费在线观看成人av| 亚洲一区欧美一区| 91久久中文| 国产原创一区二区| 欧美三级韩国三级日本三斤| 久久综合色8888| 欧美一区二区视频网站| 亚洲乱码一区二区| 欧美国产日韩亚洲一区| 欧美一区二区三区播放老司机| 曰本成人黄色| 国产日韩欧美不卡在线| 欧美三级黄美女| 欧美精品国产精品| 久久综合亚洲社区| 久久岛国电影| 午夜精品成人在线| 在线亚洲激情| 亚洲乱码国产乱码精品精可以看| 久久伊人亚洲| 久久成人精品无人区| 亚洲色图制服丝袜| 午夜亚洲性色视频| 日韩视频免费观看高清在线视频| 国产精品视频久久一区| 欧美日本免费一区二区三区| 久久精品在线观看| 性一交一乱一区二区洋洋av| 99精品欧美一区二区蜜桃免费| 久久手机精品视频| 久久久www| 久久久之久亚州精品露出| 亚洲欧美一区二区精品久久久| 亚洲精品视频在线观看网站 | 伊人久久av导航| 国产精品香蕉在线观看| 欧美日韩一本到| 欧美日韩亚洲一区二区三区在线| 久久精品夜色噜噜亚洲a∨| 亚洲一卡久久| 亚洲欧美在线视频观看| 亚洲视频在线一区观看| 亚洲午夜91| 亚洲综合大片69999| 亚洲欧美在线观看| 欧美在线影院| 久久久久一区| 免费视频一区二区三区在线观看| 久久精品男女| 久久综合狠狠综合久久综青草| 久久国产精品一区二区| 久久精品国产99国产精品澳门| 午夜精品在线观看| 欧美一二三视频| 久久人人97超碰国产公开结果| 久久国产精品久久久久久久久久 | 国产精品女同互慰在线看| 国产精品theporn| 国产三级欧美三级| 一色屋精品视频在线观看网站| 国内成人精品一区| 亚洲激情不卡| 亚洲免费中文| 免费久久99精品国产自在现线| 蜜桃久久av| 99视频精品在线| 久久gogo国模裸体人体| 欧美刺激性大交免费视频| 欧美亚洲成人精品| 怡红院精品视频在线观看极品| 亚洲风情在线资源站| 亚洲精品在线免费观看视频| 亚洲综合色在线| 另类综合日韩欧美亚洲| 亚洲精品欧美精品| 欧美一区二区三区四区视频 | 亚洲天堂偷拍| 久久久久久精| 日韩一级大片在线| 久久精品一区二区三区不卡| 欧美大片国产精品| 国产欧美一级| 亚洲免费播放| 久久综合给合久久狠狠狠97色69| 亚洲国产美国国产综合一区二区| 9人人澡人人爽人人精品| 久久精品国产久精国产思思| 欧美色欧美亚洲另类七区| 国语自产精品视频在线看一大j8 | 欧美一区二区三区视频在线| 欧美亚洲视频| 欧美日韩国产成人精品| 国产一区二区三区在线播放免费观看 | 久久久久久网站| 欧美日韩国产综合网| 国产一区深夜福利| 中国成人黄色视屏| 免费一级欧美片在线观看| 亚洲视频自拍偷拍| 欧美国产日韩视频| 在线观看国产一区二区| 小黄鸭精品aⅴ导航网站入口| 欧美激情精品久久久久久大尺度| 中国成人亚色综合网站|