CodeForces 721C Journey】的更多相关文章

$dp$,拓扑排序. 记$dp[i][j]$表示走到节点$i$,走过了$j$个点的最小时间,然后就可以递推了.要注意的是节点$1$的入度一开始不一定等于$0$. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<v…
<题目链接> 题目大意:一个DAG图有n个点,m条边,走过每条边都会花费一定的时间,问你在不超过T时间的条件下,从1到n点最多能够经过几个节点. 解题分析:对这个有向图,我们进行拓扑排序,并且在拓扑排序的过程中,用dp来进行状态的转移,$dp[i][j]$表示,在以$i$为终点的且经过$j$个点的路径中,所花的最少时间. #include <bits/stdc++.h> using namespace std; #define pb push_back ; int dp[N][N]…
起初误以为到每个叶子的概率一样于是.... /* CodeForces 839C - Journey [ DFS,期望 ] | Codeforces Round #428 (Div. 2) */ #include <bits/stdc++.h> using namespace std; const int N = 100005; int n; vector<int> G[N]; double dp[N], val[N]; bool vis[N]; void dfs(int u, i…
题目链接: C. Journey time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are n showplaces in the city,…
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output Recently Irina arrived to one of the most famous cities of Berland - the Berlatov city. There are n showplaces in the city, numbered from 1 to n…
C. Journey time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other…
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads. Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But…
题目链接:http://codeforces.com/contest/721/problem/C 题意:从1走到n,问在时间T内最多经过多少个点,按路径顺序输出. 思路:比赛的时候只想到拓排然后就不知道怎么办了......先拓扑排序,再按照拓扑的顺序进行DP,dp[to][j](到i点走过j个点最短时间) = min(dp[to][j], dp[i][j] + dis) #include<bits/stdc++.h> using namespace std; typedef long long…
[题目链接] http://codeforces.com/contest/839/problem/C [算法] 概率DP 时间复杂度 : O(N) [代码] #include<bits/stdc++.h> using namespace std; #define MAXN 100010 int tot , n; int head[MAXN]; bool visited[MAXN]; double f[MAXN]; struct edge { int to , nxt; } e[MAXN <…
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description Little boy Igor wants to become a traveller. At first, he decided to visit all the cities of his motherland - Uzhlyandia. It is widely known that Uzhlyandia has…
/* 题意:给你一个有向无环图.给一个限定t. 问从1点到n点,在不超过t的情况下,最多可以拜访几个点. 保证至少有一条路时限不超过t. 思路: 1.由无后向性我们可以知道(取决于该图是一个DAG),这题一定可以dp. 2.dp[i][j]代表,到达点i,并且拜访了j个城市的最短时间. wa点: 没有初始化数组中的0.. */ #include<bits/stdc++.h> #define N 5050 using namespace std; int inf=0x3f3f3f3f; int…
题意就是某个人去游览,起点是1点,终点是n点,他总的游览时间不能超过t,第一行给你3个数字,点的个数n,边的个数m,时间t,然后底下m行数据,每行代表一条边,边的起点,终点和权值(走过去花的时间),然后问你,她想尽量多的游览景点,还要求总时间不能超过t(他在景点不会逗留,所以只要计算路程花费的时间即可),问你怎么走,输出路径 题目我不会做,看了题解,dalao的思路的拓扑+dp,直接dp貌似不行,为什么用拓扑+dp呢- -,我感觉里面就是让你求最长的哈密顿路径- -,这就很哲学了- -,看了da…
题意:给定一个有向图,你从1出发到n,走尽可能多的点,并且使总权值不大于t. 析:在比赛时,竟然看成有向图了,就想了好久,感觉dp,但是不会啊...如果是有向图就好做多了,枚举边,然后打印就好,dp[i][j] 表示, 经过 i 个结点,并且在 j的最小时间. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #inc…
题意: n个点m条边的图,起点为1,终点为n,每一条单向边输入格式为: a,b,c     //从a点到b点耗时为c 题目问你最多从起点1到终点n能经过多少个不同的点,且总耗时小于等于t 题解: 这道题我原本以为是改一下最短路去做,,,但是想不到怎么写.网上搜了搜,发现是拓扑+dp. 拓扑排序有啥用? 比如一共有好多件事情,事情A要再事情B(或者更多)事情做完才能做,也就是给你了一种完成事件的顺序 那么转化到这道题上就是从1点到其他点有多种方式,它就是按顺序做这些事情(也就是按这个顺序dp) 那…
Journey CodeForces - 721C Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected by one-directional roads. The roads in Berlatov…
用DFS+记忆化写了一下,拓扑排序+DP的我还没弄明白.据说Codeforces 721C就是这类题目,因为有费用限制,DFS不太好写,有时间把DP法想明白来. #include <iostream> #include <cstdio> #include <vector> #include <stack> #define LL long long int using namespace std; LL sta[]; vector<]; LL dp[];…
Little boy Igor wants to become a traveller. At first, he decided to visit all the cities of his motherland — Uzhlyandia. It is widely known that Uzhlyandia has n cities connected with m bidirectional roads. Also, there are no two roads in the countr…
C. Journey 题目连接: http://codeforces.com/contest/721/problem/C Description Recently Irina arrived to one of the most famous cities of Berland - the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected…
题目链接:http://codeforces.com/problemset/problem/788/B B. Weird journey time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little boy Igor wants to become a traveller. At first, he decided to vi…
题目链接:http://codeforces.com/contest/721/problem/C C. Journey time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Recently Irina arrived to one of the most famous cities of Berland — the Berlato…
codeforces 407 div1 B题(Weird journey) 传送门 题意: 给出一张图,n个点m条路径,一条好的路径定义为只有2条路径经过1次,m-2条路径经过2次,图中存在自环.问满足条件的路径数 题解: 推论:对于一条边u-->v,我们将其选作为那两条边之一,那么剩下一条边必然与之相邻或者是自环,因为这样才能满足这两条边只走1次. 那么这条边的贡献值为这条边的相邻边数+自环数,假如这条边本身为自环,那么由于剩下的边可以任选(前一个推论),贡献值为m-1 这个AC时间很6啊23…
传送门:https://codeforces.com/gym/100801 题意: 小明坐地铁,现在有n-1种类型的地铁卡卖,现在小明需要买一种地铁票,使得他可以在t的时间内到达终点站,地铁票的属性为r,表明这个地铁票一次最多只能做r站,可以坐到当前位置的pos-r到pos+r范围的任意一站,到站后他需要花费di的时间重新上地铁. 现在问你最小的花费是多少. 题解: 已知我们可以在pos-r到pos+r内的范围的任意一站的位置下车,那么如果我范围为r的票可以在规定时间内到达终点站的话,我的r+1…
Codeforces 题面传送门 & 洛谷题面传送门 神仙题,做了我整整 2.5h,写篇题解纪念下逝去的中午 后排膜拜 1 年前就独立切掉此题的 ymx,我在 2021 年的第 5270 个小时 A 掉此题,而 ymx 在 2020 年的第 5270 就已经 A 掉了此题 %%%%%% 首先注意到一件事情,就是如果存在一个长度为 \(k\) 的 Journey,那么必然存在一个长度为 \(k\) 的 Journey,满足相邻两个字符串长度的差刚好为 \(1\)(方便起见,在后文中我们及其为 Co…
传送门:http://codeforces.com/contest/788/problem/B 好题!好题! 首先图不连通的时候肯定答案是0,我们下面讨论图联通的情况 首先考虑,如果我们每条边都经过两边,那么肯定是可行的 因为这样相当于把每条边复制一遍,然后问图中是否存在欧拉路径 既然每条边都出现了两遍,那么所有点的度数一定都是偶数,所以肯定有欧拉路径 现在考虑将某两条边变成出现一遍,这样的话可能会有一些点的度数变成奇数 如果我们把两条非自环的边变成出现一遍,并且这两条边不交于同一个点,那么就会…
D. Weird journey time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little boy Igor wants to become a traveller. At first, he decided to visit all the cities of his motherland — Uzhlyandia. I…
http://codeforces.com/contest/839/problem/C [AC] #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<cmath> using namespace std; ; struct edge { int to; int nxt; }e[maxn];…
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads. Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But…
D. Weird journey time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little boy Igor wants to become a traveller. At first, he decided to visit all the cities of his motherland — Uzhlyandia. I…
C. Journey time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are n showplaces to n, and some of them…
[题目链接]:http://codeforces.com/problemset/problem/789/D [题意] 给你n个点,m条边; 可能会有自环 问你有没有经过某两条边各一次,然后剩余m-2条边,每条边各2次的 遍历方案,有的话输出方案数 [题解] /* 把每条边都复制一条相同的边; 然后问题就能转化为在2*m条边中,去掉两条边; 然后使得剩下的图能够进行一笔画(每条边都只经过一次) 则使奇点的个数为0或为2就好了; 考虑自环边和普通边; 对于普通边来说: ①如果删掉的两条普通边是不相邻…