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\) 算法. 我们考虑给定一个图,要找 ...
随机推荐
- 设计模式(十二): Flyweight享元模式 -- 结构型模式
说明: 相对于其它模式,Flyweight模式在PHP实现似乎没有太大的意义,因为PHP的生命周期就在一个请求,请求执行完了,php占用的资源都被释放.我们只是为了学习而简单做了介绍. 1. 概述 面 ...
- Android数据存储三剑客——SharedPreferences、File、SQLite
Android中常用的数据存储一般有三种方式:SharedPreferences.文件和SQLite数据库,用来保存需要长时间保存的数据.本文将通过几个具体的小实例来讲解这三种方式的具体实现. 数据存 ...
- java泛型编程
一般的类和方法都是针对特定数据类型的,当写一个对多种数据类型都适用的类和方法时就需要使用泛型编程,java的泛型编程类似于C++中的模板,即一种参数化类型的编程方法,具体地说就是将和数据类型相关的信息 ...
- Java[4] Jetty工作原理介绍(转)
转自:https://www.ibm.com/developerworks/cn/java/j-lo-jetty/ Jetty 的工作原理以及与 Tomcat 的比较 Jetty 应该是目前最活跃也是 ...
- Fancybox——学习(1)
转载:http://www.helloweba.com/view-blog-65.html Fancybox是一款优秀的jquery插件,它能够展示丰富的弹出层效果.前面我们有文章介绍了facybox ...
- CentOS6.x升级MySQL版本号5.1到5.6
有一些虚拟机.云主机提供商仍然使用的是老版本号的安装套件. 预装的应用软件版本号非常低. 比方 techbrood.com 使用的云server,当中MySQL预装版本号为老版本号5.1.x. 而最新 ...
- 忘记mysql 5.7的密码
for windows: http://blog.chinaunix.net/uid-27570589-id-3511820.html 一.将net stop mysql; 二.在命令行中 C:\Us ...
- firefox 不能显示 glyphicons 字体
折腾了很久才发现是firefox 不能跨域下载相应的字体文件,将bootstrap相应的css文件和字体文件copy到调用的项目里,问题才得以解决.
- ASP.Net用jQuery ajax实现页面局部刷新
刚开始的时候使用asp的updatepanel控件实现局部刷新,而且在本地运行正确,但是部署到服务器上就变成整个页面全部刷新了.服务器用的是Windows server2000,本地机子上用的是win ...
- 使用证书部署出现System.Security.Cryptography.CryptographicException 错误解决方案
一.System.Security.Cryptography.CryptographicException: 找不到对象 at System.Security.Cryptography.Cryptog ...