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 ...
随机推荐
- HDU 2554 N对数的排列问题
LINK:HDU 2554 这是昨天晚上小练里面比较有趣的一道题~我在做的时候思路错了,以为数字的排列会有规律,结果后面发现就算有也很难找......╮(╯▽╰)╭ 看了网上的题解,有一种恍然大悟的感 ...
- dedecms 常用标签
都是常用的一些标签,大家可以用ctrl+F实现搜索. 网站名称:{dede:global.cfg_webname/} 网站根网址:{dede:global.cfg_basehost/} 网站根目录:{ ...
- Ubuntu 12.04 分区方案(仅供参考)
Ubuntu 12.04 分区方案(仅供参考) 总空间大小:50G 目录 建议大小 实际大小 格式 描述 / 10G~20G 10G ext4 根目录 swap <2048M 1G swap ...
- SilkTest天龙八部系列1-初始化和构造函数
SilkTest没有提供专门的构造函数机制,但是在类对象生成的过程中,会先初始化在类中申明的变量.我们可以在初始化该变量的时, 调用某些函数完成对象初始化工作,看上去好像是调用了构造函数一样.不过要记 ...
- 监控mysql索引使用效率的脚本
SELECT t.table_schema AS db, t.table_name AS tab_name, s.index_name AS index_name, s.colum ...
- linux 内核 编绎配制选项详解
http://blog.sina.com.cn/s/blog_8308bc810102ux0j.html
- Linux Ubuntu上架设FTP
操作系统:ubuntu (GNU/Linux) 为了在机子上架设ftp服务器,我们需要安装ftp服务器软件.Linux下具有代表性的ftp服务器软件有Wu-FTP,ProFTP和Vsftp.Wu-FT ...
- java窗体与Flash交互
最近在研究flash,用flash去读取文件很简单,但是存储文件就很麻烦了. 因此想到用java的窗体进行交互. 下面是DJNativeSwing-SWT-1-0-3-20140708的下载链接: h ...
- Android(java)学习笔记209:采用get请求提交数据到服务器(qq登录案例)
1.GET请求: 组拼url的路径,把提交的数据拼装url的后面,提交给服务器. 缺点:(1)安全性(Android下提交数据组拼隐藏在代码中,不存在安全问题) (2)长度有限不能超过4K(h ...
- Python中如何写控制台进度条的整理
本文实例讲述了Python显示进度条的方法,是Python程序设计中非常实用的技巧.分享给大家供大家参考.具体方法如下: 首先,进度条和一般的print区别在哪里呢? 答案就是print会输出一个\n ...