Codeforces 459E Roland and Rose
本以为是个树形DP,按照树形DP的方法在那里dfs,结果WA到死,因为它存在有向环,不是树,凡是存在环的情况切记不要用树形的方法去做
题目的突破点在于将边排完序之后,用点表示以该点为边结尾的最大长度,因为是按边排序从小到大加边,所以后面加的边肯定比前面的小。
要注意相同边的情况,要搞个缓冲,因为相同边的时候如果直接操作,可能会造成不应该有的影响。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,m;
const int N = 100010*3;
struct edge
{
int u,v,w;
bool operator < (const edge& rhs) const{
return w<rhs.w;
}
}E[N];
int dp[N];
int last[N];
int main()
{
while (scanf("%d%d",&n,&m)!=EOF)
{
for (int i=0;i<m;i++){
scanf("%d%d%d",&E[i].u,&E[i].v,&E[i].w);
}
sort(E,E+m);
memset(dp,0,sizeof dp);
memset(last,0,sizeof last);
for (int i=0;i<m;){
int j=i;
while (E[i].w==E[j].w && j<m) j++;
for (int k=i;k<j;k++){
last[E[k].v]=max(last[E[k].v],dp[E[k].u]+1);
}
for (int k=i;k<j;k++){
dp[E[k].v]=max(dp[E[k].v],last[E[k].v]);
}
i=j;
}
int ans=0;
for (int i=1;i<=n;i++){
ans=max(ans,dp[i]);
}
printf("%d\n",ans);
}
return 0;
}
Codeforces 459E Roland and Rose的更多相关文章
- Codeforces 460E Roland and Rose(暴力)
题目链接:Codeforces 460E Roland and Rose 题目大意:在以原点为圆心,半径为R的局域内选择N个整数点,使得N个点中两两距离的平方和最大. 解题思路:R最大为30.那么事实 ...
- Codeforces Round #262 (Div. 2) E. Roland and Rose 暴力
E. Roland and Rose Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/pro ...
- codeforces 459E
codeforces 459E E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabyte ...
- Codeforces 459E Pashmak and Graph(dp+贪婪)
题目链接:Codeforces 459E Pashmak and Graph 题目大意:给定一张有向图,每条边有它的权值,要求选定一条路线,保证所经过的边权值严格递增,输出最长路径. 解题思路:将边依 ...
- Codeforces 459E Pashmak and Graph
http://www.codeforces.com/problemset/problem/459/E 题意: 给出n个点,m条边的有向图,每个边有边权,求一条最长的边权上升的路径的长度. 思路:用f存 ...
- Codeforces 459E Pashmak and Graph:dp + 贪心
题目链接:http://codeforces.com/problemset/problem/459/E 题意: 给你一个有向图,每条边有边权. 让你找出一条路径,使得这条路径上的边权严格递增. 问你这 ...
- CodeForces - 459E Pashmak and Graph[贪心优化dp]
E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabytes input standard ...
- [CF460E]Roland and Rose
题意:给定$n$和$r$,要找$n$个整点,使得他们两两距离的平方和最大,并且所有点到原点的距离必须小于$r$ 很容易猜到答案在凸包上然后暴力找,但证明还是挺妙的 首先转化一下距离平方和 令$\vec ...
- 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 ...
随机推荐
- spring boot 中 2.X 的跨域请求
解决跨域: @Configuration @EnableAutoConfiguration public class ZooConfiguration { @Bean public FilterReg ...
- 使用java实现二叉查找树的插入,修改和删除方法
目前使用的是根据key的hashcode来进行排序,并且没有考虑hash碰撞的问题 package com.zhou.tree; import java.util.Comparator; import ...
- 【PAT甲级】1031 Hello World for U (20 分)
题意: 输入一个字符串长度为5~80,以'U'型输出,使得底端一行字符数量不小于侧面一列,左右两列长度相等. trick: 不把输出的数组全部赋值为空格为全部答案错误,可能不赋值数组里值为0,赋值后是 ...
- 「JOI2019 Final」解题报告
传送门 「JOI2019 Final」勇者比太郎 看懂题就很简单了,后缀和随便维护一下就好了,别用树状数组强加一个\(\log\)就行. 「JOI2019 Final」画展 显然可以先把所有的画框按大 ...
- 自定义组装json对象
组装json对象 public string strTree(DataTable dt, string type, string state) { string strjosn = "&qu ...
- PyCharm底部控制台console界面开启/取消自动换行
File --> Settings --> Editor --> General --> Console中 勾选右侧第一项Use soft wraps in console(选 ...
- Numpy中 arange() 的用法
1. 概述Numpy 中 arange() 主要是用于生成数组,具体用法如下: 2. arange()2.1 语法numpy.arange(start, stop, step, dtype = Non ...
- Python print()函数
#输出单个数据,会自动输出回车换行 print(1) print(2) #输出 1 2 #输出换行 print('\n') #防止换行 for x in range(0, 5): print(x, e ...
- routes 学习
对于routes的学习,感觉还是看官方文档理解的比较快,主要说明connect和resource Setting up routes¶ It is assumed that you are using ...
- topthink/think-swoole 扩展包的使用 之 WebSocket
嗯~ o(* ̄▽ ̄*)o,没错欢迎收看继续爬坑系列233...话不多说直接开撸 今天的题材是websocket,没有特殊说明的话默认环境都和此系列第一篇文章中申明一致,此后不再赘述. websocke ...