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. JS——放大镜

    放大镜: 1.比例系数要恒定:在系数为4的情况下,若原图是820*512,那么小图必须是205*128,放大镜若是50,原图显示区域必须200 2.计算鼠标在小图中的坐标 3.放大镜需要在鼠标中间位置 ...

  2. 惊了!!! 小白零基础学java (月薪过万是你的梦想嘛) 手把手教学 就怕你不动手【二十五】第二章【初识MySQL】

    初识MySQL1. 了解主流的数据库和数据库分类1.1 数据库概念数据库:按照数据结构来组织.存储和管理数据的一种建立在计算机存储设备上的仓库. 数据库的优势: 1. 可以持久化存储大量的数据.方便我 ...

  3. swift--Xcode7 使用Alamofire框架发送HTTP请求报错

    控制台打印的错误信息: Application Transport Security has blocked a cleartext HTTP (http://) resource load sinc ...

  4. C#学习笔记_07_数组

    07_数组 数组的声明与实例化 名词解释 数组:数组是一个容器,用来存储一系列相兼容的数据类型的变量: 实例化:声明一个数组,并且赋初始值: 数组长度:就是数组的容量,表示这个数组可以存储多少个数据: ...

  5. Beetl学习总结(2)——基本用法

    2.1. 安装 如果使用maven,使用如下坐标 <dependency> <groupId>com.ibeetl</groupId> <artifactId ...

  6. centOS下安装mysql workbench详细步骤

    step0:安装mysql 在按照workbench之前,先安装mysql.指令是 yum install mysql mysql-server mysql-libs mysql-server 关于m ...

  7. nyoj_91_阶乘之和_201312131321

    阶乘之和 时间限制:3000 ms  |           内存限制:65535 KB 难度:3   描述 给你一个非负数整数n,判断n是不是一些数(这些数不允许重复使用,且为正数)的阶乘之和,如9 ...

  8. Spring MVC的@RequestMapping多个URL映射到同一个方法

    @RequestMapping可以是一个URL对应一个方法,也可以多个URL对应同一个方法,写法如下: @RequestMapping(value={"url","res ...

  9. Spring MVC-视图解析器(View Resolverr)-多重解析器(Multiple Resolver)示例(转载实践)

    以下内容翻译自:https://www.tutorialspoint.com/springmvc/springmvc_multiple_resolver_mapping.htm 说明:示例基于Spri ...

  10. LDAP目录服务折腾之后的总结

    前言 公司管理员工信息以及组织架构的后台系统要和Active Directory目录服务系统打通,后台系统使用PHP开发, 折腾了二十多天,终于上线了,期间碰到过各种疑难问题,不过总算在GOOGLE大 ...