codeforces round 474 pathwalks
题目传送门http://codeforces.com/contest/960/problem/F
4月25号期中考,答应过年级组长要考年排前3的,所以25号以前我就不搞竞赛了,期中考要考好。
有很多大佬写了主席树(初二的弱菜并不会)。但初二的会树状数组和map呀哈哈哈哈。
做法很简单,开n个树状数组,对于每条边,我们维护走到它最多步数,也就是在它之前出现的边-1然后边权比它小的dp值的最大值+1
树状数组如果不用map会mle
上代码(dp数组就是wxy数组,至于为什么吗,看我另一篇博客就知道了~~)
#include <bits/stdc++.h>
using namespace std;
+;
int n,m,fr[N],to[N],we[N];
int lowbit(int x){return x&-x;}
struct treearr{
map<int,int>c;
void motify(int x,int d){while(x<=N){c[x]=max(c[x],d);x+=lowbit(x);}}
;while(x){res=max(res,c[x]);x-=lowbit(x);}return res;}
}wxy[N];
int main(){
scanf("%d%d",&n,&m);
int i;
;i<=m;++i){
int u,v,len;scanf("%d%d%d",&u,&v,&len);++len;fr[i]=u;to[i]=v;we[i]=len;
wxy[v].motify(len,wxy[u].qry(len)+);
}
;
;i<=n;++i)ans=max(ans,wxy[i].qry(+));
printf("%d",ans);
}
codeforces round 474 pathwalks的更多相关文章
- Divide by Zero 2018 and Codeforces Round #474 (Div. 1 + Div. 2, combined)
思路:把边看成点,然后每条边只能从下面的边转移过来,我们将边按照u为第一关键字,w为第二关键字排序,这样就能用线段树维护啦. #include<bits/stdc++.h> #define ...
- Divide by Zero 2018 and Codeforces Round #474 (Div. 1 + Div. 2, combined)G - Bandit Blues
题意:求满足条件的排列,1:从左往右会遇到a个比当前数大的数,(每次遇到更大的数会更换当前数)2.从右往左会遇到b个比当前数大的数. 题解:1-n的排列,n肯定是从左往右和从右往左的最后一个数. 考虑 ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
随机推荐
- 【LeetCode】033. Search in Rotated Sorted Array
题目: Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. ( ...
- oracle sql性能
1.查询所对象相关的表?V$LOCK, V$LOCKED_OBJECT, V$SESSION, V$SQLAREA, V$PROCESS ;查询锁的表的方法:SELECT S.SID SESSION_ ...
- bash批量处理
[root@azure_dbm1_s1 scripts]# more slave_1062_stop.sh #/bin/bash slave_num=`mysql -e "show slav ...
- Poj 1067 取石子游戏(NIM,威佐夫博奕)
一.Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的石子. ...
- 【转】 Pro Android学习笔记(五六):配置变化
目录(?)[-] Activity的destorycreate过程 Fragment的destorycreate过程 onSaveInstanceState saveFragmentInstanceS ...
- JavaScript中对象的属性
在JavaScript中,属性决定了一个对象的状态,本文详细的研究了它们是如何工作的. 属性类型 JavaScript中有三种不同类型的属性:命名数据属性(named data properties) ...
- IIS应用池保持激活工具开发
之前的 开源一个定时任务调度器 webscheduler 中涉及的定时调用应用已经开始在正式环境中启用,发布到IIS下进行测试,发现一旦应用长时间没有访问(大约半个多小时)就会引发 Applicati ...
- cdh 安装组件 异常总结
hive 启动 要 把mysql的jar包放到/opt/cloudera/parcels/CDH-5.9.3-1.cdh5.9.3.p0.4/lib/hive/lib 下 假设有3个节点就要放3次
- Java探索之旅(17)——多线程(1)
1.多线程 1.1线程 线程是程序运行的基本执行单元.指的是一段相对独立的代码,执行指定的计算或操作.多操作系统执行一个程序时会在系统中建立一个进程,而在这个进程中,必须至少建立一个线程(这个线程被 ...
- 关闭QtCreator的vim风格编辑模式
今天不小心点到了键盘的快捷键Alt+V,使QtCreator进入了vim风格编辑模式,导致快捷键拷贝粘贴都不正常,找了下资料才发现是这个问题.具体操作如下: 打开QtCreator去掉下列位置的勾选或 ...