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 ...
随机推荐
- redis的hash, list, set类型相关命令
hash相关命令: 1. hset HSET key field value 将哈希表key中的域field的值设为value.如果key不存在,一个新的哈希表被创建并进行hset操作.如果域fiel ...
- Qt5.0.2无法发布问题
先从bin目录里面找到所缺失的dll,如果出现 可以找到libEGL.dll然后复制过来就可以了.
- 关键在封装并发出了帧-IP冲突也无所谓
最近有点走火入魔了!本文所用技术非标准,较真儿者慎入!! 一个局域网内,两台机器拥有同样的IP,可以吗? 这不就是IP地址冲突吗?当然不行! 可是要知道,如果搞点旁门左道,还是可以做到的! 首先要明白 ...
- 算法之旅,直奔<algorithm>之十四 fill_n
fill_n(vs2010) 引言 这是我学习总结<algorithm>的第十四篇,作为fill的亲兄弟,fill_n也会助你一把的. 作用 fill_n 的作用是给一段指定长度的数据向量 ...
- DevExpress GridControl GridView 导出到 Excel 类
说明: 1>GridView 导出到 Excel (如果分页,只导出当前页数据) 2>GridView 导出到 Excel 3>方法2可以参考DataTable 导出到 Excel ...
- Nginx重要结构request_t解析之http请求的获取
请在文章页面明显位置给出原文连接,否则保留追究法律责任的权利. 本文主要参考为<深入理解nginx模块开发与架构解析>一书,处理用户请求部分,是一篇包含作者理解的读书笔记.欢迎指正,讨论. ...
- 【Heritrix基础教程之1】在Eclipse中配置Heritrix
一.新建项目并将Heritrix源代码导入 1.下载heritrix-1.14.4-src.zip和heritrix-1.14.4.zip两个压缩包,并解压,以后分别简称SRC包和ZIP包: 2.在E ...
- Percona-toolkit的安装和配置-杨建荣的学习笔记
http://blog.itpub.net/23718752/viewspace-2091818/#rd
- partition例子
10.13 标准库定义了名为partition的算法,它接受一个谓词,对容器内容进行划分,使得谓词为true的值会排在容器的前半部分,而使谓词为false的值会排在后半部分.算法返回一个迭代器,指向最 ...
- android 沉浸通知栏
IOS的沉浸式通知栏很高大上,通知栏和app统一颜色或样式,很美观.android上面也早就人实现这种效果了. 我在这边也写一个实现通知栏沉浸式的方法,目前只实现了相同颜色. 先要改布局文件xml & ...