CF459E Pashmak and Graph (Dag dp)】的更多相关文章

传送门 解题思路 \(dag\)上\(dp\),首先要按照边权排序,然后图都不用建直接\(dp\)就行了.注意边权相等的要一起处理,具体来讲就是要开一个辅助数组\(g[i]\),来避免同层转移. 代码 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> using namespace std; const int M…
Codeforces Round #261 (Div. 2) E - Pashmak and Graph E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Pashmak's homework is a problem about graphs. Although he always tr…
E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Pashmak's homework is a problem about graphs. Although he always tries to do his homework completely, he can't solve thi…
题意:n个点,m条边,每条边有一个权值,找一条边数最多的边权严格递增的路径,输出路径长度. 解法:先将边权从小到大排序,然后从大到小遍历,dp[u]表示从u出发能够构成的严格递增路径的最大长度. dp[u] = max(dp[u],dp[v]+1),因为有重复的边权值,所以用dis数组先记录,到不重复时一起更新重复的那些边权. 代码: (非原创) #include <iostream> #include <cstdio> #include <cstring> #incl…
题目链接:http://codeforces.com/problemset/problem/459/E 题意: 给你一个有向图,每条边有边权. 让你找出一条路径,使得这条路径上的边权严格递增. 问你这样的路径最长有多长. 题解: 先将所有边按边权从小到大排序,以保证边权递增. 表示状态: dp[i] = max len 表示以点i为终点时的最长路径长度. 找出答案: ans = max dp[i] 如何转移: 枚举每条边e[i],则有: dp[e[i].t] = max(dp[e[i].t],…
题目链接:http://codeforces.com/contest/459/problem/E 题意:给出m条边n个点每条边都有权值问如果两边能够相连的条件是边权值是严格递增的话,最长能接几条边. 题解:先按照边权排序一下,然后再利用dp求最值. 显然可以设dp[i]表示以i点为结尾最长能连几条边,dp[v]=dp[u]+1,u表示指向v的那个点,还有一点要注意的. 可能会遇到边权值相同的情况,这时候就不能这么转移了,所以在处理dp是要先处理一下边权相同的几个点. for(int i = 0…
题目链接:http://codeforces.com/contest/459/problem/E 题意:给一个带权有向图, 找出其中最长上升路的长度. 题解:先按权值对所有边排序, 然后依次 u ->v 权值w  则  f[u] = f[v] + 1; 这里需要注意的是 存在多条边权值相同, 这是应多条边一同计算. /***Good Luck***/ #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <cstd…
E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Pashmak's homework is a problem about graphs. Although he always tries to do his homework completely, he can't solve thi…
题目链接:Codeforces 459E Pashmak and Graph 题目大意:给定一张有向图,每条边有它的权值,要求选定一条路线,保证所经过的边权值严格递增,输出最长路径. 解题思路:将边依照权值排序,每次将同样权值的边同一时候增加,维护每一个点作为终止点的最大长度就可以. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn…
题目链接: E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Pashmak's homework is a problem about graphs. Although he always tries to do his homework completely, he can't sol…