题目描述 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…
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. T…
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. T…
# !/usr/bin/env/Python3 # - * - coding: utf-8 - * - from html.parser import HTMLParser import urllib.request #使用parser获取图片信息,输出Python官网发布的会议时间.名称和地点. class MyHTMLParser(HTMLParser): def __init__(self): super().__init__() self.li = False self.h3 = Fal…
题目链接 本题使用拓扑排序来规划DP顺序.设s[i][j]表示i步是否能走到j这个点,e[i][j]表示i步是否能走到j这个点——用第二条路径.因为要满足无后效性和正确性,只有第i个点已经全部更新完毕的时候才能用它来更新其他的点.所以用拓扑. 代码如下 #include<cstdio> #include<cctype> #include<cstring> #include<algorithm> using namespace std; inline long…
题面 传送门:https://www.luogu.org/problemnew/show/P3626 Solution 如果题目只要求求出第一问,那这题显然就是大水题. 但是加上第二问的话.......那这题就成为大(du)火(liu)题了. 对于第一问:求一整个区间的最大线段总数,我们可以很轻松的切掉. 怎么处理第二问呢? 我们可以考虑这样做: 对于一条线段,如果它属于答案的一部分,那么它一定会有以下性质: 区间③的最大线段数 = 区间①的最大线段数 + 区间②的最大线段数 + 1(当前线段)…
很优美的解法. 推荐大佬博客 如果没有保证字典序最小这一个要求,这题就是一个水题了,但是要保证字典序最小,然后我就不会了…… 如果一条线段能放入一个区间$[l', r']$并且不影响最优答案,那么对于这条线段$[l, r]$,设$solve(l, r)$表示$[l, r]$这个区间里面最多能放多少条线段,一定要有条件$solve(l', l - 1) + solve(r + 1, r') + 1 == solve(l', r')$. 那么贪心的时候顺便考虑一下怎么检验的问题就可以了,如果暴力检验…
题面 传送门:https://www.luogu.org/problemnew/show/P3119 Solution 这题显然要先把缩点做了. 然后我们就可以考虑如何处理走反向边的问题. 像我这样的蒟蒻,当然是使用搜索,带记忆化的那种(滑稽). 考虑设f(i,j)表示到达第i个点,还能走j次反向边,所能到达的最多的点的数量. 转移可以表示为: 如果x能到达1所在的强连通分量或max出来的值不为0,说明当前状态可行,否则不可行. 然后用记忆化搜索表达出来就OK了 Code #include<io…
思路很乱,写个博客理一理. 缩点 + dp. 首先发现把一个环上的边反向是意义不大的,这样子不但不好算,而且相当于浪费了一次反向的机会.反正一个强连通分量里的点绕一遍都可以走到,所以我们缩点之后把一个强连通分量放在一起处理. 设$st$表示缩点之后$1$所在的点,设$f_{x}$表示从$st$走到$x$的最长链,$g_{x}$表示从$x$走到$st$的最长链,因为把一个$DAG$上的边反向一下并不会走重复的点,那么我们最后枚举一下边$(x, y)$,把它反向,这样子$f_{x} + g_{y}…
题目描述 In an effort to better manage the grazing patterns of his cows, Farmer John has installed one-way cow paths all over his farm. The farm consists of N fields, conveniently numbered 1..N, with each one-way cow path connecting a pair of fields. For…