Codeforces 459E Pashmak and Graph
http://www.codeforces.com/problemset/problem/459/E
题意:
给出n个点,m条边的有向图,每个边有边权,求一条最长的边权上升的路径的长度。
思路:用f存边,g存点,然后排序转移,注意相同的要延迟转移
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
struct edge{
int u,v,w;
}e[];
int n,m,f[],g[];
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
bool cmp(edge a,edge b){
return a.w<b.w;
}
int main(){
n=read();m=read();
for (int i=;i<=m;i++){
e[i].u=read();e[i].v=read();e[i].w=read();
}
std::sort(e+,e++m,cmp);
int t=,ans=;
for (int i=;i<=m;i++){
f[i]=g[e[i].u]+;
if (e[i].w!=e[i+].w){
for (int j=t;j<=i;j++)
g[e[j].v]=std::max(g[e[j].v],f[j]);
t=i+;
}
ans=std::max(ans,f[i]);
}
printf("%d\n",ans);
return ;
}
Codeforces 459E Pashmak and Graph的更多相关文章
- Codeforces 459E Pashmak and Graph(dp+贪婪)
题目链接:Codeforces 459E Pashmak and Graph 题目大意:给定一张有向图,每条边有它的权值,要求选定一条路线,保证所经过的边权值严格递增,输出最长路径. 解题思路:将边依 ...
- CodeForces - 459E Pashmak and Graph[贪心优化dp]
E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces 459E Pashmak and Graph:dp + 贪心
题目链接:http://codeforces.com/problemset/problem/459/E 题意: 给你一个有向图,每条边有边权. 让你找出一条路径,使得这条路径上的边权严格递增. 问你这 ...
- 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 459E
codeforces 459E E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabyte ...
- 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 ...
- codeforces 459D - Pashmak and Parmida's problem【离散化+处理+逆序对】
题目:codeforces 459D - Pashmak and Parmida's problem 题意:给出n个数ai.然后定义f(l, r, x) 为ak = x,且l<=k<=r, ...
- ACM - 最短路 - CodeForces 295B Greg and Graph
CodeForces 295B Greg and Graph 题解 \(Floyd\) 算法是一种基于动态规划的算法,以此题为例介绍最短路算法中的 \(Floyd\) 算法. 我们考虑给定一个图,要找 ...
随机推荐
- use "man rsyslogd" for details. To run rsyslog interactively, use "rsyslogd -n"to run it in debug mo
zjtest7-frontend:/root# service rsyslog start Starting system logger: usage: rsyslogd [options] use ...
- FFT修正
#include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #inc ...
- 【转】单双精度浮点数的IEEE标准格式
原文网址:http://blog.chinaunix.net/uid-24118190-id-75212.html 单双精度浮点数的IEEE标准格式 关键字:浮点数 IEEE标准 大多数高级语言按照I ...
- 【转】ubuntu连接android设备(附最简单方法)
原文网址:http://blog.csdn.net/maosidiaoxian/article/details/22661725 在ubuntu下连接android设备,虽然不用像windows那样安 ...
- windows下MongoDB的安装及配置
http://jingyan.baidu.com/article/d5c4b52bef7268da560dc5f8.html 使用MongoVUE链接本地mongodb 基本用法见这里:http:// ...
- HDU5266---pog loves szh III (线段树+LCA)
题意:N个点的有向树, Q次询问, 每次询问区间[L, R]内所有点的LCA. 大致做法:线段树每个点保存它的孩子的LCA值, 对于每一次询问只需要 在线段树查询即可. #include <bi ...
- SQL Server 启用 xp_cmdshell 与bcp 使用
启用 xp_cmdshell 1: sp_configure 'show advanced options',1 2: reconfigure 3: GO 4: 5: sp_configure 'xp ...
- C++编程规范之12:懂得何时和如何进行并发性编程
摘要: 如果应用程序使用了多个线程或者进程,应该知道如何尽量减少共享对象,以及如何安全地共享必须共享的对象. 在多线程和并发编程中最重要的是要避免死锁.活锁和恶性的竞争条件. 在编写多线程程序时要注意 ...
- 手贱随手在Linux敲了 as 命令,出不来了
手贱随手在Linux敲了 as 命令,出不了命令,问问度娘吧,得到下列资料 as命令 GNU组织推出的一款汇编语言编译器,它支持多种不同类型的处理器.语法as(选项)(参数)选项-ac:忽略失败条 ...
- htm初学笔记
一.什么是html HTML(HyperText Markup Language):超文本标记语言,一种纯文本类型的语言 --使用带有尖括号的“标记”将网页中的内容逐一标识出来 用来设计网页的标记语言 ...