传送门

按照时间t排序

如果 t[i] + map[i][j] <= t[j],就在i和j之间连一条边

然后spfa找最长路

#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 401 using namespace std; int n, ans, cnt;
int a[N][N], map[N][N], dis[N], head[N], to[N * 100], next[N * 100];
bool vis[N];
queue <int> q; struct node
{
int t, id;
}p[N]; inline int read()
{
int x = 0, f = 1;
char ch = getchar();
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
return x * f;
} inline bool cmp(node x, node y)
{
return x.t < y.t;
} inline void spfa()
{
int i, u, v;
q.push(0);
while(!q.empty())
{
u = q.front();
q.pop();
vis[u] = 0;
for(i = head[u]; ~i; i = next[i])
{
v = to[i];
if(dis[v] < dis[u] + 1)
{
dis[v] = dis[u] + 1;
if(!vis[v])
{
q.push(v);
vis[v] = 1;
}
}
}
}
} inline void add(int x, int y)
{
to[cnt] = y;
next[cnt] = head[x];
head[x] = cnt++;
} int main()
{
int i, j, k;
n = read();
memset(head, -1, sizeof(head));
for(i = 1; i <= n; i++)
p[i].id = i, p[i].t = read();
for(i = 1; i <= n; i++)
for(j = 1; j <= n; j++)
map[i][j] = read();
sort(p + 1, p + n + 1, cmp);
for(i = 1; i <= n; i++) map[0][i] = map[1][i];
p[0].id = p[0].t = 0;
for(i = 0; i <= n; i++)
for(j = i + 1; j <= n; j++)
if(p[i].t + map[p[i].id][p[j].id] <= p[j].t)
add(p[i].id, p[j].id);
spfa();
for(i = 1; i <= n; i++) ans = max(ans, dis[i]);
printf("%d\n", ans);
return 0;
}

  

最新文章

  1. [ 技术人员创业Tips ] 1:抓住优质客户(上)
  2. C#中日期记忆日期的格式化,日期格式化说明
  3. 夺命雷公狗----Git---7---GitHub当仓库本地使用(完)
  4. 浅谈Java五大设计原则之代理模式
  5. (原创)android中使用相机的两种方式
  6. CoolTrayIcon4.0
  7. Oracle rowid
  8. &quot;ORA-12154: TNS:could not resolve the connect identifier specified&quot;的解决办法
  9. 烂泥:KVM虚拟机克隆
  10. php--数据库三范式
  11. c# 事件为何要继承EventArgs
  12. Edit Control的Enter响应函数
  13. 网站在域名前面添加logo小图标
  14. (hdu)1042 N! 大数相乘
  15. No bean named &#39;sessionFactory&#39; is defined
  16. Python集合set
  17. 读书笔记--《gongchandang宣言》
  18. @angular/cli 工程 项目 配置
  19. BZOJ1433或洛谷2055 [ZJOI2009]假期的宿舍
  20. MongoDB pymongo模块 更新数据

热门文章

  1. freebsd自动获取ip地址
  2. win10下vs2013为程序集新建强名称文件时“未能完成操作。拒绝访问”的解决方案
  3. Oracle 存储过程调用语句
  4. UVA1665 Islands (并查集)
  5. @ConditionalOnProperty来控制Configuration是否生效
  6. C# DateTime.Now函数
  7. IE6 bug总结
  8. python:lambda、filter、map、reduce
  9. java中regex参考
  10. rocketmq 命令示例