Jam's store

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 61    Accepted Submission(s): 18

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

 
思路:
很经典的建图,需要记住。
此题中,顾客的修理时间会影响到后续顾客的等待时间,而该名顾客何时修理并不能确定,所以枚举该位顾客在所有店员的修理队伍的位置以及对后续顾客的时间影响。
所以我们如下建图:先建立虚拟起点到每个顾客的边,然后我们将每个店员拆成 N 个点,第 i 个顾客是电源 j 的倒数第 k 个顾客:add( i, j‘, k * c ),其中 j' 是拆点后的点的编号,c 即是顾客在该店员修理花费的时间。最后将所有店员都连接到虚拟汇点即可。
 
代码如下:
 #include <bits/stdc++.h>
using namespace std;
typedef int MyType;
const MyType INF = 0x7F7F7F7F;
const int MAXN = + ;
const int MAXM = + ; struct Edge { int to, next; MyType cap, cost; };
Edge es[MAXM];
int head[MAXN], dis[MAXN], pre[MAXN], que[MAXM], a[MAXN][MAXN];
bool vis[MAXN];
int n, m, cnt, src, des; void add( int u, int v, MyType f, MyType c ) {
es[cnt].to = v; es[cnt].cap = f; es[cnt].cost = c;
es[cnt].next = head[u]; head[u] = cnt++;
es[cnt].to = u; es[cnt].cap = ; es[cnt].cost = -c;
es[cnt].next = head[v]; head[v] = cnt++;
return ;
} bool spfa() {
int mf, me;
memset( vis, false, sizeof( vis ) );
memset( dis, 0x7F, sizeof( dis ) );
memset( pre, -, sizeof( pre ) );
mf = me = ;
que[me++] = src; dis[src] = ; vis[src] = true;
while( mf != me ) {
int u = que[mf++]; vis[u] = false;
if( mf >= MAXM ) mf -= MAXM;
for( int i = head[u]; ~i; i = es[i].next ) {
int v = es[i].to;
if( es[i].cap > && dis[v] > dis[u] + es[i].cost ) {
dis[v] = dis[u] + es[i].cost;
pre[v] = i;
if( !vis[v] ) {
vis[v] = true;
que[me++] = v;
if( me >= MAXM ) me -= MAXM;
}
}
}
}
return dis[des] != INF;
} MyType cflow() {
MyType flow = INF;
int u = des;
while( ~pre[u] ) {
u = pre[u];
flow = min( flow, es[u].cap );
u = es[u ^ ].to;
}
u = des;
while( ~pre[u] ) {
u = pre[u];
es[u].cap -= flow;
es[u ^ ].cap += flow;
u = es[u ^ ].to;
}
return flow;
} MyType MCMF() {
MyType mincost, maxflow;
mincost = maxflow = ;
while( spfa() ) {
MyType flow = cflow();
maxflow += flow;
mincost += flow * dis[des];
}
return mincost;
} int main() {
int t;
scanf( "%d", &t );
while( t-- ) {
scanf( "%d%d", &m, &n );
memset( head, -, sizeof( head ) ); cnt = ;
for( int i = ; i <= n; ++i ) {
for( int j = ; j <= m; ++j )
scanf( "%d", &a[i][j] );
}
src = ; des = ;
int ncnt = n + ;
for( int i = ; i <= n; ++i ) add( src, i, , );
for( int i = ; i <= m; ++i ) {
for( int j = ; j <= n; ++j ) {
++ncnt;
for( int k = ; k <= n; ++k ) {
add( k, ncnt, , a[k][i] * j );
}
add( ncnt, des, , );
}
}
printf( "%d\n", MCMF() );
}
return ;
}

HDU 5619 Jam's store的更多相关文章

  1. cdq分治(hdu 5618 Jam's problem again[陌上花开]、CQOI 2011 动态逆序对、hdu 4742 Pinball Game、hdu 4456 Crowd、[HEOI2016/TJOI2016]序列、[NOI2007]货币兑换 )

    hdu 5618 Jam's problem again #include <bits/stdc++.h> #define MAXN 100010 using namespace std; ...

  2. HDU 5616 Jam's balance(Jam的天平)

    HDU 5616 Jam's balance(Jam的天平) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K ...

  3. HDU 5616 Jam's balance(DP)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=5616 题目: Jam's balance Time Limit: 2000/1000 MS (Java ...

  4. HDU 5616 Jam's balance(01背包)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=5616 题目: Jam's balance Time Limit: 2000/1000 MS (Java ...

  5. HDU 5615 Jam's math problem

    Jam's math problem Problem Description Jam has a math problem. He just learned factorization.He is t ...

  6. HDU 5618 Jam's problem again(三维偏序,CDQ分治,树状数组,线段树)

    Jam's problem again Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  7. HDU 5617 Jam's maze dp+滚动数组

    题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5617 bc(中文):http://bestcoder.hdu.edu.cn/contest ...

  8. hdu 5616 Jam's balance 正反背包+转换

    http://acm.hdu.edu.cn/showproblem.php?pid=5616 思路 题目中蕴含着两种需要计算的重量 1. 从所有的砝码中挑出任意种2.(转换的思想)在天平的两端都挑出这 ...

  9. hdu 5615 Jam's math problem(十字相乘判定)

    d. Jam有道数学题想向你请教一下,他刚刚学会因式分解比如说,x^2+6x+5=(x+1)(x+5) 就好像形如 ax^2+bx+c => pqx^2+(qk+mp)x+km=(px+k)(q ...

随机推荐

  1. JDBC与SQL SERVER各个版本的连接方法

    转至:blog.csdn.net/ying5420/article/details/4488246 1.SQL SERVER 2000 JDBC驱动程序:msbase.jar.mssqlserver. ...

  2. mybatis的$存在安全问题,为什么又不得不用?

    1.mybatis的官网关于$和#的字符串替换符号区别描述如下: http://www.mybatis.org/mybatis-3/zh/sqlmap-xml.html#Parameters 上面的意 ...

  3. 在C#中我们能调用一个类的私有方法吗

    博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:在C#中我们能调用一个类的私有方法吗.

  4. cocos2d-x 卡牌翻牌效果的实现

    转自:http://blog.csdn.net/yanghuiliu/article/details/9115833 这个能实现翻牌的action就是CCOrbitCamera. static CCO ...

  5. How Many Fibs_hdu_1316(大数).java

    How Many Fibs? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  6. Integer Inquiry_hdu_1047(大数).java

    Integer Inquiry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. jquery选择器及效率问题

    $('p2') //选择名字 $('.class') //选择class $('#id') //选择id $('#id li') //所有id=”id”标签内的li标签 $(“#id”).find(“ ...

  8. Android中FTP服务器、客户端搭建以及SwiFTP、ftp4j介绍

    本文主要内容: 1.FTP服务端部署---- 基于Android中SwiFTP开源软件介绍: 2.FTP客户端部署 --- 基于ftp4j开源jar包的客户端开发 : 3.使用步骤 --- 如何测试我 ...

  9. Bash String Manipulation Examples – Length, Substring, Find and Replace--reference

    In bash shell, when you use a dollar sign followed by a variable name, shell expands the variable wi ...

  10. 普通SQL注入

    安全防御:过滤/转义非法参数,屏蔽SQL查询错误. 工具:Firefox,hackbar,sqlmap,burpsuite 1.联想tms站 例1, 联想tms站fromCity参数存在普通SQL注入 ...