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 ...
随机推荐
- gem install 和 bundle 区别
bundle install 在设置了所有包含在Gemfile中的东西.你也可以传递参数. 如果在production模式下,你很清晰的区分了每个app需要的gems. gem install 则安装 ...
- DragonBones龙骨骨骼中的自定义事件(另有声音、动画事件)
参考: DragonBones骨骼动画事件系统详解 一.在DragonBones中添加自定义事件帧 动画制作时 时间轴拉到最下面有一个事件层,添加一个事件帧 左边属性面板定义自定义事件 二.Egret ...
- ElasticSearch 简单入门
英文原文:Getting Started with ElasticSearch 原文链接:http://www.oschina.net/translate/elasticsearch-getting- ...
- 【BZOJ5090】组题 分数规划
[BZOJ5090]组题 Description 著名出题人小Q的备忘录上共有n道可以出的题目,按照顺序依次编号为1到n,其中第i道题目的难度系数被小Q估计为a_i,难度系数越高,题目越难,负数表示这 ...
- 【BZOJ1417】Pku3156 Interconnect 记忆化搜索
[BZOJ1417]Pku3156 Interconnect Description 给出无向图G(V, E). 每次操作任意加一条非自环的边(u, v), 每条边的选择是等概率的. 问使得G连通的期 ...
- python之接口
首先,我们必须明确的一点是:python里无接口类型,定义接口只是一个人为规定,在编程过程自我约束 python的类是可以写任意个方法的 定义一个接口对继承类进行约束,接口里有什么方法,继承类就必须有 ...
- PKCS 发布的15 个标准与X509
PKCS 发布的15 个标准,转自:http://falchion.iteye.com/blog/1472453 PKCS 全称是 Public-Key Cryptography Standards ...
- R数据可视化手册学习简单的绘制常见的图形
1.绘制散点图 # 使用ggplot2 library(ggplot2) ggplot(data = mtcars, aes(x = wt, y = mpg)) + geom_point() 2.绘制 ...
- debug $mysqli->character_set_name();
<?php $mysqli = new mysqli('localhost', 'root', '', 'w'); if(mysqli_connect_errno()){ printf('Con ...
- veterbi
https://www.zhihu.com/question/20136144 作者:知乎用户链接:https://www.zhihu.com/question/20136144/answer/372 ...