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 ...
随机推荐
- Python-S9-Day89_stark总结
01 Stark总结 02 ORM总结 03 上节作业 04 Stark组件之查看页面表头 05 list_display_links 06 stark组件之添加页面 07 编辑删除页面 01 Sta ...
- Android实现金额显示小数点后两位
代码改变世界 Android实现金额显示小数点后两位 NumberFormat nf = new DecimalFormat("##.##"); Double d = 554545 ...
- BZOJ 4326:NOIP2015 运输计划(二分+差分+lca)
NOIP2015 运输计划Description公元 2044 年,人类进入了宇宙纪元.L 国有 n 个星球,还有 n−1 条双向航道,每条航道建立在两个星球之间,这 n−1 条航道连通了 L 国的所 ...
- arcsde10.0 for oracle11g 分布式安装教程
[操作系统] oracle :windows server 2008ArcSDE:win7[数据库版本] Oracle 11g [ArcSDE版本] ArcSDE 10.0 1.在要安装ArcSD ...
- C#中找不到MouseWheel事件的解决办法
在.....Designer.cs中加入 this.pictureBox1.MouseWheel += new System.Windows.Forms.MouseEventHandler(this. ...
- hdu 4096 判断路径
思路:将每个关系当成一条有向边,查询时就判断之间存在路径. #include<iostream> #include<cstdio> #include<cstring> ...
- filesystem
1 tmpfs 以下来源于维基百科: tmpfs是类Unix系统上暂存档存储空间的常见名称,通常以挂载文件系统方式实现,并将数据存储在易失性存储器而非永久存储设备中.和RAM disk的概念近似,但后 ...
- fetch上传cookie数据方法
Fetch 请求默认是不带cookie的.需要设置fetch的第二个参数: 先来看下,请求头部信息Request method - 使用的HTTP动词,GET, POST, PUT, DELETE, ...
- react当中子组件改变父组件的状态
子组件直接改变父组件传入的props值是不被允许的, 当需要在子组件当中改变父组件的某一个状态, 父组件传入一个改变状态的函数,然后在子组件当中调用函数即可
- 【BZOJ4402】Claris的剑(组合计数)
题意: 给定数列的定义: 1.每个元素都是正整数 2.每个元素不能超过M 3.相邻两个元素的差的绝对值必须是1 4.第一个元素的值必须是1 求有多少个长度不超过N的合法的本质不同的序列 两个序列本质不 ...