hdoj--5619--Jam's store(最小费用最大流)
来源:互联网 发布:淘宝上有卖少女脚皮的 编辑:程序博客网 时间:2024/06/04 22:30
Jam's store
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 134 Accepted Submission(s): 49
Problem Description
Jam didn't study well,then he go to repair the computer in a store,there areM staffs and N guests, given each guests have to spend Tij time to repair the computer by the j staffs.
Now ask the total of time the guest at least to wait.
The staff wiil do the next work after he has done the current work
Now ask the total of time the guest at least to wait.
The staff wiil do the next work after he has done the current work
Input
The first line is T(1≤T≤100) means T Case
For each case
The first line isM and N(1≤M,N≤20) means the number of staffs and guests
Now given a Matrix withN∗M each number means the i guests to the j staff time (1≤Tij≤1000)
For each case
The first line is
Now given a Matrix with
Output
Output one line about the time at least they need to wait
Sample Input
14 34 4 1 58 2 5 64 5 10 5
Sample Output
7Hintthe first guest choose the third staffthe second guest choose the second staffthe third gurst choose the third staffthe total of time is 4+2+1=7一道比较裸的最大流,刚开始想得有点简单,建图的时候应该是需要分层的,m个服务人员n个顾客,完全可能出现所有的顾客都去一个服务人员那边的情况,所以应该分成n层,对顾客顾客排序,一个顾客的编号可以使1--n,他后边可能有k个人,所以后边的人是需要等k*time,这就是边权,然后就是建立超级源点跟超级汇点,跑一边最大流#include<cstdio>#include<cstring>#include<queue>#include<cmath>#include<algorithm>using namespace std;#define MAXN 5000+10#define MAXM 800000+10#define INF 0x3f3f3f3fint head[MAXN],cnt;struct node{int u,v,cap,flow,cost,next;}edge[MAXM];int pre[MAXN],dis[MAXN];bool vis[MAXN];void init(){cnt=0;memset(head,-1,sizeof(head));}void add(int u,int v,int w,int c){node E={u,v,w,0,c,head[u]};edge[cnt]=E;head[u]=cnt++;node E1={v,u,0,0,-c,head[v]};edge[cnt]=E1;head[v]=cnt++;}bool BFS(int s,int t){queue<int>q;memset(dis,INF,sizeof(dis));memset(pre,-1,sizeof(pre));memset(vis,false,sizeof(vis));dis[s]=0;vis[s]=true;q.push(s);while(!q.empty()){int u=q.front();q.pop();vis[u]=false;for(int i=head[u];i!=-1;i=edge[i].next){node E=edge[i];if(dis[E.v]>dis[E.u]+E.cost&&E.cap>E.flow){dis[E.v]=dis[E.u]+E.cost;pre[E.v]=i;if(!vis[E.v]){vis[E.v]=true;q.push(E.v);}}}}return pre[t]!=-1;}void MCMF(int s,int t,int &cost,int &flow){cost=flow=0;while(BFS(s,t)){int Min=INF;for(int i=pre[t];i!=-1;i=pre[edge[i^1].v]){node E=edge[i];Min=min(Min,E.cap-E.flow);}for(int i=pre[t];i!=-1;i=pre[edge[i^1].v]){edge[i].flow+=Min;edge[i^1].flow-=Min;cost+=Min*edge[i].cost;}flow+=Min;}}int main(){int t;scanf("%d",&t);while(t--){int n,m;scanf("%d%d",&m,&n);int S=0,T=n+n*m+1;init();for(int i=1;i<=n;i++){add(S,i,1,0);for(int j=1;j<=m;j++){int time;scanf("%d",&time);for(int k=1;k<=n;k++)add(i,j*n+k,1,k*time);}}for(int i=1;i<=m;i++)for(int j=1;j<=n;j++)add(i*n+j,T,1,0);int flow,cost;MCMF(S,T,cost,flow);printf("%d\n",cost);}return 0;}
0 0
- hdoj--5619--Jam's store(最小费用最大流)
- hdoj 5619 Jam's store 【最小费用最大流】
- hdu 5619 Jam's store(最小费用最大流)
- HDU5619 Jam's store(最小费用最大流 MCMF)
- HDU 5619 Jam's store(最小费用最大流-mcmf)
- hdu 5619 Jam's store (费用流)
- HDU 5619 Jam's store (费用流,建图巧妙)
- HDOJ 4862 Jump(最小费用最大流)
- hdoj 2282 Chocolate 【最小费用最大流】
- hdoj 4494 Teamwork 【最小费用最大流】
- hdu 5619 Jam's store
- poj 3686 The Windy's(最小费用最大流)
- hdu5352 MZL's City(最小费用最大流问题)
- Hdu 5352 MZL's City (最小费用最大流)
- BestCoder Round #70 Jam's store(网络流)
- hdu 5619 Jam's store (mcmf)
- HDOJ 3677 - Transportation 构图拆边,最小费用最大流
- hdoj 3488,2696 ,3435 【经典最小费用最大流】
- 定位的一个yaffs2文件系统的bug
- CodeForces 608 A. Saitama Destroys Hotel(水~)
- 数据库备份了解
- Messenger(信使)
- 2015年第六届蓝桥杯C/C++程序设计本科B组省赛 牌型种数(结果填空)
- hdoj--5619--Jam's store(最小费用最大流)
- Redis与MySql结合
- 数据结构 栈 链表
- 百度2014笔试算法题
- HOJ 2985 Wavio Sequence(最长递增子序列以及其O(n*logn)算法)
- UILabel / UITextView load HTML文本
- Cocos2d-x 3.x数据存储(UserDefault)
- Leetcode_299_Bulls and Cows
- Android事件机制