CodeForces - 459E

Posted lesning

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces - 459E相关的知识,希望对你有一定的参考价值。

 

 

 技术图片

 

 

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#define maxn 300030
using namespace std;
struct Node {
	int be;
	int en;
	int len;
}que[maxn];
bool bml(Node a, Node b) {
	return a.len < b.len;
}
int n, m;
int list[maxn];
int ans[maxn];
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++) {
		scanf("%d%d%d", &que[i].be, &que[i].en, &que[i].len);
	}
	sort(que, que + m, bml);
	int t = 0;
	int xx = 0;
	for (int i = 0; i < m; i++) {
		int x = que[i].be;
		int p = que[i].en;
		int len = que[i].len;
		list[i] = ans[x] + 1;
		
		if (len != que[i + 1].len) {
			for (int j = t; j <= i; j++) {
				ans[que[j].en] = max(ans[que[j].en], list[j]);
			}
			t = i + 1;
		}
		xx = max(xx, list[i]);
	}
	printf("%d
", xx);
	return 0;
}

  

以上是关于CodeForces - 459E的主要内容,如果未能解决你的问题,请参考以下文章

CodeForces 459E Pashmak and Graph:dp + 贪心

CF459E Pashmak and Graph

[Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)][C. Playing Piano](代码片段

c_cpp Codeforces片段

Codeforces 86C Genetic engineering(AC自动机+DP)

CodeForces 1005D Polycarp and Div 3(思维贪心dp)