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\) 算法. 我们考虑给定一个图,要找 ...
随机推荐
- [转载]memcached stats 命令
STAT pid 1552 STAT uptime 3792 STAT time 1262517674 STAT version 1.2.6 STAT pointer_size 32 STAT cur ...
- HDOJ(HDU) 1555 How many days?(水题)
Problem Description 8600的手机每天消费1元,每消费K元就可以获赠1元,一开始8600有M元,问最多可以用多少天? Input 输入包括多个测试实例.每个测试实例包括2个整数M, ...
- JavaScript 随机数函数
Math.random()*(m-n)+n random函数语法 Math.random(); random函数返回值 返回0和1之间的伪随机数,可能为0,但总是小于1,[0,1) 返回10-20 ...
- Android中AsyncTask的简单用法 .
在开发Android应用时必须遵守单线程模型的原则: Android UI操作并不是线程安全的并且这些操作必须在UI线程中执行.在单线程模型中始终要记住两条法则: 1. 不要阻塞UI线程 2. 确保只 ...
- LaTeX笔记
1.上下标: $x^n$, $x^{123}$, $x_n$, $x_{123}$, $C_n^m$, $C_{100}^{50}$ $x^n$, $x^{123}$, $x_n$, $x_{123} ...
- python数据库做成邮箱的注册系统!
#! /usr/bin/env python2.7 # -*- coding:utf-8 -*- #File:w7.py #Date:2013-7-18 #Author:wangyu import r ...
- sql列转行
1.需要实现一个单行的统计报表 思路先用一个union查出单列,然后再把单列转成单行 2.实现 SELECT MAX(CASE WHEN type = 1 THEN num ELSE 0 END) A ...
- Python之基础(二)
1.内建函数enumerate friends = ['john', 'pat', 'gary', 'michael'] for i, name in enumerate(friends): prin ...
- Movie播放Gif,完美实现屏幕适配
android播放gif 我研究过3种 第一 :GifView支持android播放gif,效果是 先加载第一帧,然后慢慢加载完其他的针,这样效果视觉很不好,是从模糊到清晰的过程:第二:是流行的把g ...
- C#和.NET Framework
.NET Framework概述 .NET Framework是由微软开发,一个致力于敏捷软件开发.快速应用开发.平台无关性和网络透明化的软件开发平台. .NET Framework组成 .NET F ...