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 are
M
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
 
Input
The first line is T(1≤T≤100)
means T
Case



For each case



The first line is M
and N(1≤M,N≤20)
means the number of staffs and guests



Now given a Matrix with N∗M
each number means the i
guests to the j
staff time (1≤Tij≤1000)
 
Output
Output one line about the time at least they need to wait
 
Sample Input
1
4 3
4 4 1 5
8 2 5 6
4 5 10 5
 
Sample Output
7
Hint
the first guest choose the third staff
the second guest choose the second staff
the third gurst choose the third staff
the 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 0x3f3f3f3f
int 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;
}

hdoj--5619--Jam's store(最小费用最大流)的更多相关文章

  1. hdoj 1533 Going Home 【最小费用最大流】【KM入门题】

    Going Home Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  2. HDU3376 最小费用最大流 模板2

    Matrix Again Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)To ...

  3. [板子]最小费用最大流(Dijkstra增广)

    最小费用最大流板子,没有压行.利用重标号让边权非负,用Dijkstra进行增广,在理论和实际上都比SPFA增广快得多.教程略去.转载请随意. #include <cstdio> #incl ...

  4. bzoj1927最小费用最大流

    其实本来打算做最小费用最大流的题目前先来点模板题的,,,结果看到这道题二话不说(之前打太多了)敲了一个dinic,快写完了发现不对 我当时就这表情→   =_=你TM逗我 刚要删突然感觉dinic的模 ...

  5. ACM/ICPC 之 卡卡的矩阵旅行-最小费用最大流(可做模板)(POJ3422)

    将每个点拆分成原点A与伪点B,A->B有两条单向路(邻接表实现时需要建立一条反向的空边,并保证环路费用和为0),一条残留容量为1,费用为本身的负值(便于计算最短路),另一条残留容量+∞,费用为0 ...

  6. HDU5900 QSC and Master(区间DP + 最小费用最大流)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5900 Description Every school has some legends, ...

  7. P3381 【模板】最小费用最大流

    P3381 [模板]最小费用最大流 题目描述 如题,给出一个网络图,以及其源点和汇点,每条边已知其最大流量和单位流量费用,求出其网络最大流和在最大流情况下的最小费用. 输入输出格式 输入格式: 第一行 ...

  8. 【BZOJ-3876】支线剧情 有上下界的网络流(有下界有源有汇最小费用最大流)

    3876: [Ahoi2014]支线剧情 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 821  Solved: 502[Submit][Status ...

  9. hdu 4411 2012杭州赛区网络赛 最小费用最大流 ***

    题意: 有 n+1 个城市编号 0..n,有 m 条无向边,在 0 城市有个警察总部,最多可以派出 k 个逮捕队伍,在1..n 每个城市有一个犯罪团伙,          每个逮捕队伍在每个城市可以选 ...

  10. UVa11082 Matrix Decompressing(最小费用最大流)

    题目大概有一个n*m的矩阵,已知各行所有数的和的前缀和和各列所有数的和的前缀和,且矩阵各个数都在1到20的范围内,求该矩阵的一个可能的情况. POJ2396的弱化版本吧..建图的关键在于: 把行.列看 ...

随机推荐

  1. MySQL数据库的三大范式定义,作用—------你所期待的最佳答案

    第一范式:确保每列的原子性. 如果每列(或者每个属性)都是不可再分的最小数据单元(也称为最小的原子单元),则满足第一范式. 例如:顾客表(姓名.编号.地址.……)其中"地址"列还可 ...

  2. JS——样式类的添加

    1.注意current前有个空格 this.className = this.className + " current"; 2.直接将class所有的值替换成current th ...

  3. 实验2 C++数组与指针

    一.实验目的: 掌握一维数组和二维数组的定义.赋值和输入输出的方法. 掌握字符数组和字符串函数的使用. 通过实验进一步掌握指针的概念,会定义和使用指针变量. 能正确使用数组的指针和指向数组的指针变量. ...

  4. hibernate注解之@Onetomany、@Manytoone、@JoinColumn

    @Onetomany用于实体类与数据库表映射中少的一方,请看下面的例子. 假设一个用户只有一种角色,用户和角色是onetomany的关系 用户实体 @Entity @Table(name=" ...

  5. cstring 转 string

    都通过基本类型来转换即可:CString可以转换为基本类型LPCTSTR,LPCTSTR根据项目编码可以是const char*或者const wchar_t*:string可以用c_str()转换为 ...

  6. CAD处理键盘按钮被释放(com接口VB语言)

    主要用到函数说明: MxDrawXCustomEvent::KeyUp 键盘按钮被释放,详细说明如下: 参数 说明 iVk 是按钮码,如F8,的值为#define VK_F8 0x77 返回0消息继续 ...

  7. [API 开发管理] 分享几个 eoLinker 实用操作技巧

    一键离线导出项目,PDF.WORD等格式任你挑选 举例说明,如果我要将 "示例素材项目" 导出到本地,并且以 PDF 的格式保存. 首先找到该项目所在空间:演示空间,在左边一级菜单 ...

  8. linq 升序排序 空值放后面并根据另一个字段进行多重排序

    List<PickingInfo> res = GetDatas(); var _d = (from e in res select new { aa = e.pickingLibrary ...

  9. Python----递归------Eight Queens 八皇后问题

    递归思想是算法编程中的重要思想. 作为初学者,对递归编程表示很蒙逼,每次遇到需要递归的问题,心里就有一万头草泥马飞过~~~~~~(此处略去一万头草泥马) 在B站看数据结构与算法的视频时,视频中给了两个 ...

  10. vim使用配置-python

    安装vundle git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim 添加配置文件 vim ~/.v ...