cf 459E
cf459E 这题说的是 给定一个n点m条边的带边权的有向图,从中找出一条路径(可以带环),该路径包含的边数最多,并且要求路径中的权值必须严格递增,然后对边进行排序完个后采用dp去解特殊判断一下边权值相等的时候就ok了
#include <iostream>
#include <string.h>
#include <cstdio>
#include <algorithm>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
const int maxn = *;
struct edg{
int a,b,w;
bool operator <(const edg A)const {
return w<A.w||( w == A.w &&a<A.a );
}
void read(int &a1,int &b1, int &w1 ){
a1 = a;
b1= b;
w1=w;
}
}E[maxn];
__int64 dp[][maxn];
int ma[][maxn];
int main(int argc, char *argv[]) {
int n,m;
while(scanf("%d%d",&n,&m)==){
for(int i = ; i< m; ++i)
scanf("%d%d%d",&E[i].a,&E[i].b,&E[i].w);
sort(E,E+m);
memset(dp,,sizeof(dp));
memset(ma,,sizeof(ma));
__int64 ans=;
for(int i =; i< m; ++i){
int a,b,w;
E[i].read(a,b,w);
if(w > ma[][a] && dp[][b] < dp[][a]+ ){
if(ma[][b] != w){
ma[][b] = ma[][b];
dp[][b] = dp[][b];
}
dp[][b]=dp[][a]+;
ma[][b]=w;
} else if(w>ma[][a]&&dp[][b]<dp[][a] +){
if(ma[][b] != w){
ma[][b] = ma[][b];
dp[][b] = dp[][b];
}
dp[][b]=dp[][a]+;
ma[][b]=w;
}
ans = ans> dp[][b]? ans : dp[][b];
}
printf("%I64d\n",ans);
}
return ;
}
de
cf 459E的更多相关文章
- CF 459A && 459B && 459C && 459D && 459E
http://codeforces.com/contest/459 A题 Pashmak and Garden 化简化简水题,都告诉平行坐标轴了,数据还出了对角线,后面两个点坐标给的范围也不错 #in ...
- ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'
凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...
- codeforces 459E
codeforces 459E E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabyte ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
- ARC下OC对象和CF对象之间的桥接(bridge)
在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...
- [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现
1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...
- CF memsql Start[c]UP 2.0 A
CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...
- CF memsql Start[c]UP 2.0 B
CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...
随机推荐
- [深入浅出Cocoa]iOS网络编程之Socket
http://blog.csdn.net/kesalin/article/details/8798039 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] [深入浅出Co ...
- R因子
factor(x = character(), levels, labels = levels, exclude = NA, ordered = is.ordered(x), nmax = NA) l ...
- python模块路径
Python会在以下路径中搜索它想要寻找的模块: 1. 程序所在的文件夹 2. 标准库的安装路径 3. 操作系统环境变量PYTHONPATH所包含的路径 将自定义库的路径添加到Python的库路径中去 ...
- 【巷子】---webpack配置非CMD规范的模块
一.前言 webpack在配置多页面开发的时候 ,发现用 import 导入 Zepto 时,会报 Uncaught TypeError: Cannot read property 'createEl ...
- informix数据库知识积累
一.嵌套查询 informix子查询:嵌套查询(1)select first 20 * from (select first 40 * from hlrquery_log order by id de ...
- 初次安装hive-2.1.0启动报错问题解决方法
首次安装hive-2.1.0,通过bin/hive登录hive shell命令行,报错如下: [hadoop@db03 hive-2.1.0]$ bin/hive which: no hbase in ...
- Metricbeat 的使用
目标 统计并展示系统的信息 cpu, 内存等 (当然metricbeat能收集的信息种类还很多) 前提 版本: 5.x 已经安装了ELK (elasticsearch, logstash (可选), ...
- android stream media
http://www.cnblogs.com/skyseraph/archive/2012/03/31/2427593.html http://www.cnblogs.com/lingyunhu/p/ ...
- javaScript 载入自执行
1.注册可以直接调用f()中的b(),c(),d() .原因?自己想. <!DOCTYPE html> <html> <head> <meta charset ...
- sql server内置存储过程、查看系统信息
1.检索关键字:sql server内置存储过程,sql server查看系统信息 2.查看磁盘空间:EXEC master.dbo.xp_fixeddrives , --查看各个数据库所在磁盘情况S ...