http://poj.org/problem?id=3216

n个地点,m个任务

每个任务有工作地点,开始时间,持续时间

最少派多少人可以完成所有的任务

传递闭包之后最小路径覆盖

#include<cstdio>
#include<cstring>
#include<iostream> using namespace std; #define N 21
#define M 201 int n,m; int f[N][N]; bool mp[M][M]; int pos[M],start[M],last[M]; bool vis[M];
int match[M]; void read(int &x)
{
x=; int f=; char c=getchar();
while(!isdigit(c)) { if(c=='-') f=-; c=getchar(); }
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
x*=f;
} void floyd()
{
for(int k=;k<=n;++k)
for(int i=;i<=n;++i)
for(int j=;j<=n;++j)
f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
} void build()
{
memset(mp,false,sizeof(mp));
for(int i=;i<=m;++i)
for(int j=;j<=m;++j)
{
if(i!=j)
{
if(start[i]+last[i]+f[pos[i]][pos[j]]<=start[j]) mp[i][j]=true;
}
}
} bool go(int u)
{
for(int i=;i<=m;++i)
{
if(!vis[i] && mp[u][i])
{
vis[i]=true;
if(!match[i] || go(match[i]))
{
match[i]=u;
return true;
}
}
}
return false;
} void Hungary()
{
memset(match,,sizeof(match));
int cnt=;
for(int i=;i<=m;++i)
{
fill(vis+,vis+m+,);
if(go(i)) cnt++;
}
cout<<m-cnt<<'\n';
} int main()
{
int inf;
while()
{
read(n); read(m);
if(!n) return ;
memset(f,,sizeof(f));
inf=f[][];
for(int i=;i<=n;++i)
for(int j=;j<=n;++j)
{
read(f[i][j]);
if(f[i][j]==-) f[i][j]=inf;
} floyd();
for(int i=;i<=m;++i) read(pos[i]),read(start[i]),read(last[i]);
build();
Hungary();
}
}
Repairing Company
Time Limit: 1000MS   Memory Limit: 131072K
Total Submissions: 7383   Accepted: 1993

Description

Lily runs a repairing company that services the Q blocks in the city. One day the company receives M repair tasks, the ith of which occurs in block pi, has a deadline ti on any repairman’s arrival, which is also its starting time, and takes a single repairman di time to finish. Repairmen work alone on all tasks and must finish one task before moving on to another. With a map of the city in hand, Lily want to know the minimum number of repairmen that have to be assign to this day’s tasks.

Input

The input contains multiple test cases. Each test case begins with a line containing Q and M (0 < Q ≤ 20, 0 < M ≤ 200). Then follow Q lines each with Q integers, which represent a Q × Q matrix Δ = {δij}, where δij means a bidirectional road connects the ith and the jth blocks and requires δij time to go from one end to another. If δij = −1, such a road does not exist. The matrix is symmetric and all its diagonal elements are zeroes. Right below the matrix are M lines describing the repairing tasks. The ith of these lines contains piti and di. Two zeroes on a separate line come after the last test case.

Output

For each test case output one line containing the minimum number of repairmen that have to be assigned.

Sample Input

1 2
0
1 1 10
1 5 10
0 0

Sample Output

2

poj 3216 Repairing Company的更多相关文章

  1. POJ 3216 Repairing Company(最小路径覆盖)

    POJ 3216 Repairing Company id=3216">题目链接 题意:有m项任务,每项任务的起始时间,持续时间,和它所在的block已知,且往返每对相邻block之间 ...

  2. poj 3216 Repairing Company(最短路Floyd + 最小路径覆盖 + 构图)

    http://poj.org/problem?id=3216 Repairing Company Time Limit: 1000MS   Memory Limit: 131072K Total Su ...

  3. POJ 3216 最小路径覆盖+floyd

    Repairing Company Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 6646   Accepted: 178 ...

  4. 搜索+剪枝 POJ 1416 Shredding Company

    POJ 1416 Shredding Company Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5231   Accep ...

  5. Repairing Company(poj 3216)

    题目大意: 有Q个地点,告诉你Q个地点之间的相互距离(从i地点赶到j地点需要的时间).有M项任务, 给你M项任务所在的地点block.开始时间start和任务完成需要时间time.一个工人只有在 他准 ...

  6. POJ 1416 Shredding Company【dfs入门】

    题目传送门:http://poj.org/problem?id=1416 Shredding Company Time Limit: 1000MS   Memory Limit: 10000K Tot ...

  7. 二分+动态规划 POJ 1973 Software Company

    Software Company Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 1112   Accepted: 482 D ...

  8. poj 1416 Shredding Company( dfs )

    我的dfs真的好虚啊……,又是看的别人的博客做的 题目== 题目:http://poj.org/problem?id=1416 题意:给你两个数n,m;n表示最大数,m则是需要切割的数. 切割m,使得 ...

  9. OpenJudge 2803 碎纸机 / Poj 1416 Shredding Company

    1.链接地址: http://poj.org/problem?id=1416 http://bailian.openjudge.cn/practice/2803 2.题目: 总时间限制: 1000ms ...

随机推荐

  1. A Survey on the Security of Stateful SDN Data Planes

    论文摘要: 本文为读者提供新兴的SDN带状态数据平面,集中关注SDN数据平面编程性带来的隐患. I部分 介绍 A.带状态SDN数据平面的兴起 B.带状态数据平面带来的安全隐患 引出带状态数据平面的安全 ...

  2. 第二次作业<2>

    自学计划 应为对网络的教程并不了解,所以-- 我扒了一遍同学的博客,找到了两个课程. 慕课网 和 这个. 选择这两个教程主要是深入浅出,比较合理. 开始先两个课程相互应证,多了解以后可能会选择一个.虽 ...

  3. Java中DAO的实现

    J2EE 开发人员使用数据访问对象(Data Access Object DAO)设计模式,以便将低级别的数据访问逻辑与高级别的业务逻辑分离.实现 DAO 模式涉及比编写数据访问代码更多的内容.在本文 ...

  4. 0422数学口袋精灵bug发现

    团队成员的博客园地址: 蔡彩虹:http://home.cnblogs.com/u/caicaihong/ 曾治业:http://www.cnblogs.com/zzy999/ 蓝叶:http://w ...

  5. Hadoop初探

    本文转自:https://blog.csdn.net/column/details/14334.html 前言 Hadoop是什么? 用百科上的话说:“Hadoop是一个由Apache基金会所开发的分 ...

  6. [C/C++] multimap查找一个key对应的多个value

    在multimap中,同一个键关联的元素必然相邻存放.基于这个事实,就可以将某个键对应的值一一输出. 1.使用find和count函数.count函数求出某个键出现的次数,find函数返回一个迭代器, ...

  7. 计算机网络-将C网192.168.25.0划分四个子网,计算每个子网的有效IP地址范围和对应网络掩码

    首先计算子网掩码: 将256/4=64,主机块大小64 2的6次方=64 根据主机数量计算出掩码的最后一个字节为11000000,用十进制表示掩码为255.255.255.192 由于IP地址结尾全为 ...

  8. using关键字

    声明导入名称空间 处理实现了IDisposeable的对象,并在作用域末尾调用Dispose方法

  9. HDU 6184 Counting Stars

    Problem Description Little A is an astronomy lover, and he has found that the sky was so beautiful!S ...

  10. hdu 5475 (线段树)

    An easy problem Time Limit: 8000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...