HDU 5619 Jam's store
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
4 3
4 4 1 5
8 2 5 6
4 5 10 5
Sample Output
7
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
#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的更多相关文章
- 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; ...
- HDU 5616 Jam's balance(Jam的天平)
HDU 5616 Jam's balance(Jam的天平) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K ...
- HDU 5616 Jam's balance(DP)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=5616 题目: Jam's balance Time Limit: 2000/1000 MS (Java ...
- HDU 5616 Jam's balance(01背包)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=5616 题目: Jam's balance Time Limit: 2000/1000 MS (Java ...
- HDU 5615 Jam's math problem
Jam's math problem Problem Description Jam has a math problem. He just learned factorization.He is t ...
- 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 ...
- HDU 5617 Jam's maze dp+滚动数组
题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5617 bc(中文):http://bestcoder.hdu.edu.cn/contest ...
- hdu 5616 Jam's balance 正反背包+转换
http://acm.hdu.edu.cn/showproblem.php?pid=5616 思路 题目中蕴含着两种需要计算的重量 1. 从所有的砝码中挑出任意种2.(转换的思想)在天平的两端都挑出这 ...
- 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 ...
随机推荐
- 北京Uber优步司机奖励政策(2月6日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- 如何用jQuery实现在鼠标滚动后导航栏保持固定
要实现如下效果,鼠标滚动后,上方导航栏置顶固定 关键html代码: <div class="header-bottom"> <div class="co ...
- 特殊的反转单链表算法(C++)
普通的单链表反转算法 大学的时候也做过好几次单链表的反转,记得当时都是用三个变量不断修改next的值然后实现反转. ListNode* reverseList(ListNode* head) { Li ...
- Python学习(2)
python基础学习(二)2.1 python定义函数用def,没有返回类型?def myabs(x) if x>0: return x python定义的函数可以多个直接一起返回,这一点和ja ...
- window下 Mongodb无法访问28107的有关问题(转)
原文链接:http://www.myexception.cn/go/1956868.html Mongodb无法访问28107的问题 0:环境 os:window7 64位 mongodb版本:3.0 ...
- Spring 3.0 注解注入详解
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- 每天进步一点达——MySQL——myisampack
一. 简单介绍 myisampack是一个压缩使用MyISAM引擎表的工具,通常会压缩40%~70%,当须要訪问数据.server会将所须要的信息读入到内存中.所以当訪问详细记录时,性能 ...
- Splay Tree的删除操作
Splay Tree的插入操作,搜索操作,和删除操作都实现了,那么就能够使用来解题了. 指针的删除操作的处理还是那么难的,非常多坎须要避开. 同一个坎还是坑了我好多次,就是指针传递的问题,什么时候须要 ...
- 分布式助手Zookeeper(一)
分布式助手Zookeeper(一)博客分类: Zookeeper Zookeeper最早是Hadoop的一个子项目,主要为Hadoop生态系统中一些列组件提供统一的分布式协作服务,在2010年10 ...
- C# - 转换
无论什么类型 它们存储的其实都是一系列的位 在将A类型转换为B类型时 如果能完整转换 那么系统会将两个操作数自动进行隐式转换 但也有可能因为A类型的存储位数比B类型的存储位数大 那么B类型可能就没有足 ...