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 ...
随机推荐
- asp.net core配置下载文件
asp.net core的wwwroot文件夹下默认时保存静态文件的地方,外面可以直接访问,但是如果是一些无法识别的后缀文件,如(.apk),会报错404 如果想要实现下载这些文件,在配置静态文件中间 ...
- Unity表面着色器
表面着色器和之前无光照着色器不同,其中没有顶点着色器和片元着色器,而增加了光照函数: 接下写了一个求两个贴图的光照效果 两个贴图做插值运算: Shader "Custom/SurfaceSh ...
- python中numpy.concatenate()函数的使用
numpy库数组拼接np.concatenate 原文:https://blog.csdn.net/zyl1042635242/article/details/43162031 思路:numpy提供了 ...
- nginx 跨域设置
upstream nginx { ip_hash; server weight=; server weight=; } server { listen ; server_name www.enjoy. ...
- ProgressBarForm 进度条
ProgressBarForm public partial class ProgressBarForm : Form { private Panel panel1 = new System.Wind ...
- JS html页面
js窗口置顶 if (window != top) top.location.href = location.href; js打开新窗口 js window.open()弹出窗口参数说明及居中设置 f ...
- Nacos client 客户端cpu占用100% 问题排查和解决方案
Nacos version:1.1.3client version:1.0.0 dependency: 'org.springframework.cloud:spring-cloud-alibaba- ...
- 发送邮件功能 Service 层
package com.thinkgem.jeesite.modules.yudengjipush.service; import java.text.ParseException; import j ...
- SpringMVC配置没有任何问题根据请求却怎么都找不到映射(tomcat所导致的问题)
本人在做SpringMVC练习的时候,配置文件反复检查了不下十几遍,没有任何问题,然后就招了个之前的项目的源码复制进去,原来的项目没有任何问题,这个项目却怎么都不能跳转路径,然后有找了一个Spring ...
- reactor---元数据驱动的表单
class NameForm extends React.Component { constructor(props) { super(props); this.state = { ...