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. Yii Listview 更新及搜索

    更新: http://my.oschina.net/shixiaobao17145/blog/130992 http://www.yiiframework.com/forum/index.php/to ...

  2. POJ3111 K Best

    Description Demy has n jewels. Each of her jewels has some value vi and weight wi. Since her husband ...

  3. C#- 布署WinForm程序

    1:新建安装部署项目 打开VS,点击新建项目,选择:其他项目类型->安装与部署->安装向导(安装项目也一样),然后点击确定.(详细见下图) ,此主题相关图片如下: 2:安装向导 关闭后打开 ...

  4. iOS从生成证书到打包上架-02(详细2016-10最新)

    由于篇幅的限制,这篇接着上一篇(关于证书)写的,有需要的小伙伴可以先阅读上一篇 2.在App Store创建应用 1.回到Account,点击iTunes Connect 2.点击我的App 3.点击 ...

  5. android httpClient 支持HTTPS的2种处理方式

    摘自: http://www.kankanews.com/ICkengine/archives/9634.shtml 项目中Android https或http请求地址重定向为HTTPS的地址,相信很 ...

  6. 【转】oracle创建表空间

    原文:http://www.cnblogs.com/netsql/articles/1745978.html 注意点: 1.如果在PL/SQL 等工具里打开的话,直接修改下面的代码中[斜体加粗部分]执 ...

  7. HDU - 1693 Eat the Trees(多回路插头DP)

    题目大意:要求你将全部非障碍格子都走一遍,形成回路(能够多回路),问有多少种方法 解题思路: 參考基于连通性状态压缩的动态规划问题 - 陈丹琦 下面为代码 #include<cstdio> ...

  8. java10 WeakHashMap

    WeakHashMap: 对象所占用的区域是不能直接操作的,都是通过引用来操作. 引用分类: .强引用(StrongReference):gc(垃圾回收机制)运行时不回收.例如字符串常量池.字符串虽然 ...

  9. google perftools分析程序性能

    Google perftools 1.功能简介 它的主要功能就是通过采样的方式,给程序中cpu的使用情况进行“画像”,通过它所输出的结果,我们可以对程序中各个函数(得到函数之间的调用关系)耗时情况一目 ...

  10. java与.net比较学习系列开发环境和常用调试技巧常用操作快捷键

    调试         F5 F11 调试运行   CTRL+F5 暂无 非调试运行   F6 不适用 编译整个解决方案   SHIFT+F6 不适用 编译当前选择的工程   SHIFT+F5 CTRL ...