Pashmak and Graph(dp + 贪心)
题目链接: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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <functional>
#include <cmath> #define Zero(a) memset(a, 0, sizeof(a))
#define Neg(a) memset(a, -1, sizeof(a))
#define All(a) a.begin(), a.end()
#define PB push_back
#define inf 0x3f3f3f3f
#define inf2 0x7fffffffffffffff
#define ll long long
using namespace std;
//#pragma comment(linker, "/STACK:102400000,102400000")
const int maxn = ;
int dp[maxn], dp2[maxn];
int rec[maxn];
int n, e;
struct node {
int u, v;
int w;
}edge[maxn]; bool cmp(node a, node b) {
return a.w < b.w;
}
int main() {
//freopen("data.out", "w", stdout);
//freopen("data.in", "r", stdin);
//cin.sync_with_stdio(false);
scanf("%d%d", &n, &e);
int u, v, w;
for (int i = ; i < e; ++i) {
scanf("%d%d%d", &u, &v, &w);
edge[i].u = u;
edge[i].v = v;
edge[i].w = w;
}
sort(edge, edge + e, cmp);
int j;
for (int i = ; i < e; ++i) {
for (j = i; j < e && edge[j].w == edge[i].w; ++j); for (int k = i; k < j; ++k) {
dp2[edge[k].v] = max(dp2[edge[k].v], dp[edge[k].u] + );
}
for (int k = i; k < j; ++k) {
dp[edge[k].v] = dp2[edge[k].v];
}
i = j - ;
}
int ans = ;
for (int i = ; i <= n; ++i) {
ans = max(ans, dp[i]);
}
cout << ans << endl;
return ;
}
Pashmak and Graph(dp + 贪心)的更多相关文章
- Codeforces 459E Pashmak and Graph(dp+贪婪)
题目链接:Codeforces 459E Pashmak and Graph 题目大意:给定一张有向图,每条边有它的权值,要求选定一条路线,保证所经过的边权值严格递增,输出最长路径. 解题思路:将边依 ...
- codeforces 459E E. Pashmak and Graph(dp+sort)
题目链接: E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabytes input st ...
- Codeforces Round #261 (Div. 2) E. Pashmak and Graph DP
http://codeforces.com/contest/459/problem/E 不明确的是我的代码为啥AC不了,我的是记录we[i]以i为结尾的点的最大权值得边,然后wa在第35 36组数据 ...
- CodeForces - 459E Pashmak and Graph[贪心优化dp]
E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabytes input standard ...
- CF459E Pashmak and Graph (DP?
Codeforces Round #261 (Div. 2) E - Pashmak and Graph E. Pashmak and Graph time limit per test 1 seco ...
- cf459E Pashmak and Graph
E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 【bzoj4027】[HEOI2015]兔子与樱花 树形dp+贪心
题目描述 很久很久之前,森林里住着一群兔子.有一天,兔子们突然决定要去看樱花.兔子们所在森林里的樱花树很特殊.樱花树由n个树枝分叉点组成,编号从0到n-1,这n个分叉点由n-1个树枝连接,我们可以把它 ...
- BZOJ 2021 [Usaco2010 Jan]Cheese Towers:dp + 贪心
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2021 题意: John要建一个奶酪塔,高度最大为m. 他有n种奶酪.第i种高度为h[i]( ...
- 洛谷P2507 [SCOI2008]配对 题解(dp+贪心)
洛谷P2507 [SCOI2008]配对 题解(dp+贪心) 标签:题解 阅读体验:https://zybuluo.com/Junlier/note/1299251 链接题目地址:洛谷P2507 [S ...
- Codeforces 459E Pashmak and Graph:dp + 贪心
题目链接:http://codeforces.com/problemset/problem/459/E 题意: 给你一个有向图,每条边有边权. 让你找出一条路径,使得这条路径上的边权严格递增. 问你这 ...
随机推荐
- jmeter-控制业务比例
方式一: 多线程组 缺点:由于各事务相应时间一般不一致,故只能粗略的控制业务占比 实例:待补充
- Linux shell脚本笔记
shell 命令解释器 是用来解释用户对系统的操作 使用 cat /etc/shells 可以查看 系统安装的shell Linux 启动过程: BIOS -> MBR -> BootLo ...
- 21.Linux系统服务之大坑
1.CentOS6启动流程 2.CentOS7启动流程 3.C6和C7的区别 4.运行级别C6&C7 0 关机 1 单用户模式 (超级权限 必须面对实体硬件) 2 暂未使用 3 字符界面(黑框 ...
- Redis学习四(运维指南).
一.上线规划 一般 redis 的参数配置都在 redis.conf 中,在上线前根据实际环境配置好合适参数,能有效提高 redis 的可用性. redis 的运行机器 CPU 不求核数多,但求主频高 ...
- ESP8266开发之旅 网络篇⑨ HttpClient——ESP8266HTTPClient库的使用
授人以鱼不如授人以渔,目的不是为了教会你具体项目开发,而是学会学习的能力.希望大家分享给你周边需要的朋友或者同学,说不定大神成长之路有博哥的奠基石... QQ技术互动交流群:ESP8266&3 ...
- PHP5底层原理之变量
PHP5底层原理之变量 变量结构 zval 结构体 PHP 所有类型的变量在底层都会以 zval 结构体的形式实现 (源码文件Zend/zend.h) 源码根目录搜索 grep -rin --colo ...
- 《编写可维护的JavaScript》 笔记
<编写可维护的JavaScript> 笔记 我的github iSAM2016 概述 本书的一开始介绍了大量的编码规范,并且给出了最佳和错误的范例,大部分在网上的编码规范看过,就不在赘述 ...
- 重磅!微软发布 Visual Studio Online:Web 版 VS Code + 云开发环境
北京时间 2019 年 11 月 4 日,在 Microsoft Ignite 2019 大会上,微软正式发布了 Visual Studio Online (VS Online)公开预览版! 如今发布 ...
- Spring入门介绍
概述 下载地址:https://repo.spring.io/release/org/springframework/spring/ spring是开源的轻量级框架 spring核心的主要两部分 AO ...
- [考试反思]0917csp-s模拟测试45:天命
又倒一了. 关于心态,有不少想说的. 首先旁边坐了一个kx.他上来入手T1没多久就切了然后开始对拍拍了几十万组AC. 然而我觉得T1是神仙题.先进T2. 挺简单的,5分钟出正解,然后在打出来的时候突然 ...