luogu P3116 [USACO15JAN]会议时间Meeting Time
题目描述
Bessie and her sister Elsie want to travel from the barn to their favorite field, such that they leave at exactly the same time from the barn, and also arrive at exactly the same time at their favorite field.
The farm is a collection of N fields (1 <= N <= 100) numbered 1..N, where field 1 contains the barn and field N is the favorite field. The farm is built on the side of a hill, with field X being higher in elevation than field Y if X < Y. An assortment of M paths connect pairs of fields. However, since each path is rather steep, it can only be followed in a downhill direction. For example, a path
connecting field 5 with field 8 could be followed in the 5 -> 8 direction but not the other way, since this would be uphill. Each pair of fields is connected by at most one path, so M <= N(N-1)/2.
It might take Bessie and Elsie different amounts of time to follow a path; for example, Bessie might take 10 units of time, and Elsie 20. Moreover, Bessie and Elsie only consume time when traveling on paths between fields -- since they are in a hurry, they always travel through a field in essentially zero time, never waiting around anywhere.
Please help determine the shortest amount of time Bessie and Elsie must take in order to reach their favorite field at exactly the same moment.
给出一个n个点m条边的有向无环图,每条边两个边权。
n<=100,没有重边。
然后要求两条长度相同且尽量短的路径,
路径1采用第一种边权,路径2采用第二种边权。
没有则输出”IMPOSSIBLE”
输入输出格式
输入格式:
INPUT: (file meeting.in)
The first input line contains N and M, separated by a space.
Each of the following M lines describes a path using four integers A B C D, where A and B (with A < B) are the fields connected by the path, C is the time required for Bessie to follow the path, and D is the time required for Elsie to follow the path. Both C and D are in the range 1..100.
输出格式:
OUTPUT (file meeting.out)
A single integer, giving the minimum time required for Bessie and
Elsie to travel to their favorite field and arrive at the same moment.
If this is impossible, or if there is no way for Bessie or Elsie to reach
the favorite field at all, output the word IMPOSSIBLE on a single line.
输入输出样例
3 3
1 3 1 2
1 2 1 2
2 3 1 2
2
说明
SOLUTION NOTES:
Bessie is twice as fast as Elsie on each path, but if Bessie takes the
path 1->2->3 and Elsie takes the path 1->3 they will arrive at the
same time.
bool型,如果为true表示该点可以在该时间到达,反之不行。
遍历从第一个点开始能到达的所有的点,能的话为ture ,遍历dp[n][1……10000]是否可以满足两个dp同时为真,不
能为impossible,因为每条边最多是100,从第一个点走到最后一个点最多有100条边,所以一定是小于10000的
#include<iostream>
#include<cstdio> const int N=;
bool dp[][N];
bool dp2[][N]; struct node {
int v,next,w1,w2;
}edge[N];
int num,head[N];
void add_edge(int u,int v,int w1,int w2)
{
edge[++num].v=v;edge[num].w1=w1;edge[num].w2=w2;edge[num].next=head[u];head[u]=num;
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
int u,v,a1,a2;
for(int i=;i<=m;i++)
{
scanf("%d%d%d%d",&u,&v,&a1,&a2);
add_edge(u,v,a1,a2);
}
dp[][]=dp2[][]=;
for(int i=;i<=n;i++)
{
for(int j=head[i];j;j=edge[j].next)
{
int v=edge[j].v;
for(int k=edge[j].w1;k<=;k++)
dp[v][k]|=dp[i][k-edge[j].w1];
for(int k=edge[j].w2;k<=;k++)
dp2[v][k]|=dp2[i][k-edge[j].w2];
}
}
for(int i=;i<=;i++)
if(dp[n][i]&&dp2[n][i])
{
printf("%d\n",i);
return ;
}
printf("IMPOSSIBLE\n");
return ;
}
luogu P3116 [USACO15JAN]会议时间Meeting Time的更多相关文章
- P3116 [USACO15JAN]会议时间Meeting Time
P3116 [USACO15JAN]会议时间Meeting Time 题目描述 Bessie and her sister Elsie want to travel from the barn to ...
- 洛谷P3116 [USACO15JAN]约会时间Meeting Time
P3116 [USACO15JAN]约会时间Meeting Time 题目描述 Bessie and her sister Elsie want to travel from the barn to ...
- #使用parser获取图片信息,输出Python官网发布的会议时间、名称和地点。
# !/usr/bin/env/Python3 # - * - coding: utf-8 - * - from html.parser import HTMLParser import urllib ...
- 【Luogu】P3116会议时间(拓扑排序,DP)
题目链接 本题使用拓扑排序来规划DP顺序.设s[i][j]表示i步是否能走到j这个点,e[i][j]表示i步是否能走到j这个点——用第二条路径.因为要满足无后效性和正确性,只有第i个点已经全部更新完毕 ...
- [Luogu P3626] [APIO2009] 会议中心
题面 传送门:https://www.luogu.org/problemnew/show/P3626 Solution 如果题目只要求求出第一问,那这题显然就是大水题. 但是加上第二问的话...... ...
- Luogu 3626 [APIO2009]会议中心
很优美的解法. 推荐大佬博客 如果没有保证字典序最小这一个要求,这题就是一个水题了,但是要保证字典序最小,然后我就不会了…… 如果一条线段能放入一个区间$[l', r']$并且不影响最优答案,那么对于 ...
- [Luogu P3119] [USACO15JAN]草鉴定Grass Cownoisseur (缩点+图上DP)
题面 传送门:https://www.luogu.org/problemnew/show/P3119 Solution 这题显然要先把缩点做了. 然后我们就可以考虑如何处理走反向边的问题. 像我这样的 ...
- Luogu 3119 [USACO15JAN]草鉴定Grass Cownoisseur
思路很乱,写个博客理一理. 缩点 + dp. 首先发现把一个环上的边反向是意义不大的,这样子不但不好算,而且相当于浪费了一次反向的机会.反正一个强连通分量里的点绕一遍都可以走到,所以我们缩点之后把一个 ...
- luogu P3119 [USACO15JAN]草鉴定Grass Cownoisseur
题目描述 In an effort to better manage the grazing patterns of his cows, Farmer John has installed one-w ...
随机推荐
- sql中比较大小
if object_id('tempdb..#dataOldNew1') is not null drop table #dataOldNew1 select distinct store_cd ,i ...
- Spring---环境搭建与包介绍
jar包下载路径 首先需要下载Spring框架 spring-framework-5.0.0.RELEASE-dist,官方地址为https://repo.spring.io/release/org/ ...
- Redis实现之对象(二)
列表对象 列表对象的编码可以是ziplist或者linkedlist,ziplist编码的列表对象使用压缩列表作为底层实现,每个压缩列表节点(entry)保存了一个列表元素.举个栗子,如果我们执行RP ...
- mybatis特殊字符处理
在mybatis 的mapper.xml文件中特殊字符处理方式 仅供参考 出处:http://yaobenzhang.blog.163.com/blog/static/214395113201561 ...
- python拼接
拼接: name=zhuhuan age=23 salary=333 info=''' ----- info of %s----- age:%s name:%s salary:%s %(name,ag ...
- 菜鸟之路——机器学习之KNN算法个人理解及Python实现
KNN(K Nearest Neighbor) 还是先记几个关键公式 距离:一般用Euclidean distance E(x,y)√∑(xi-yi)2 .名字这么高大上,就是初中学的两点间的距离 ...
- Oracle 查看锁定对象 解锁
一些ORACLE中的进程被杀掉后,状态被置为"killed",但是锁定的资源很长时间不释放,有时实在没办法,只好重启数据库.现在提供一种方法解决这种问题,那就是在ORACLE中杀不 ...
- [oldboy-django][2深入django]ORM操作
推荐学习博客:http://www.cnblogs.com/wupeiqi/articles/6216618.html 需求: 汇总django orm操作,代替原生mysql语句来操作数据库:里面内 ...
- docker log 批量删除报错: find: `/var/lib/docker/containers/': 没有那个文件或目录
问题描述: 服务器上面docker log太多,打算用之前写的批量清理shell脚本清理掉,但是发现报错. find: `/var/lib/docker/containers/': 没有那个文件或目录 ...
- [cocos2dx utils] cocos2dx读取,解析csv文件
在我们的游戏中,经常需要将策划的数值配置成csv文件,所以解析csv文件就是一个很common的logic, 例如如下csv文件: 下面是一个基于cocos2dx 2.2.4的实现类: #ifndef ...