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. 单调队列(数列中长度不超过k的子序列和的最值)

    ★实验任务 小 F 很爱打怪,今天因为系统 bug,他提前得知了 n 只怪的出现顺序以及击 倒每只怪得到的成就值 ai.设第一只怪出现的时间为第 1 秒,这个游戏每过 1 秒 钟出现一只新怪且没被击倒 ...

  2. JabRef学习笔记(一)

    JabRef简介 JabRef is an open source bibliography reference manager. The native file format used by Jab ...

  3. paperOne基于java web的简易四则运算出题网站

    项目成员:张金生     张政 需求概要 1.运算数均为正整数 2.包含的运算符有+,-,*,/ 3.除法运算结果为整除运算 4.批量生成题目并判题 核心功能分析 1.题目生成——java后端 题目生 ...

  4. redis哨兵机制二(转)

    概述 Redis-Sentinel是Redis官方推荐的高可用性(HA)解决方案,当用Redis做Master-slave的高可用方案时,假如 master宕机了,Redis本身(包括它的很多客户端) ...

  5. C#全局钩子和局部钩子记录

    源自:https://blog.csdn.net/programvae/article/details/80292076 最近碰巧要使用键盘钩子,于是在网上搜索了一番,发现大多数博客的文章都是雷同的, ...

  6. 高性能页面加载技术--BigPipe设计原理及Java简单实现

    1.技术背景 动态web网站的历史可以追溯到万维网初期,相比于静态网站,动态网站提供了强大的可交互功能.经过几十年的发展,动态网站在互动性和页面显示效果上有了很大的提升,但是对于网站动态网站的整体页面 ...

  7. ubuntu 16.04 部署 pypy+nginx+uwsgi+django(详细)

    1.nginx                                                                                             ...

  8. Hashtable 和 HashMap 以及 ConcurrentHashMap

    备忘: ConcurrentHashMap与Hashtable的区别: Hashtable中采用的锁机制是一次锁住整个hash表,从而同一时刻只能由一个线程对其进行操作:而ConcurrentHash ...

  9. Springboot返回html

    注:Springboot的版本2.1.3.RELEASE List-1 application.properties文件 server.port=8080 #url中,项目的前缀 server.ser ...

  10. 【BZOJ3551】Peaks加强版(Kruskal重构树,主席树)

    [BZOJ3551]Peaks加强版(Kruskal重构树,主席树) 题面 BZOJ Description 在Bytemountains有N座山峰,每座山峰有他的高度h_i.有些山峰之间有双向道路相 ...