• Codeforces 459E Pashmak and Graph


    题意:给你一个有向边权图,问你其中最长的边值单调递增的链有多长。

    解题思路:对边的长度进行排序,然后再进行分层dp(边长度相同的为一层)。

    解题代码:

     1 // File Name: 459e.cpp
     2 // Author: darkdream
     3 // Created Time: 2015年03月13日 星期五 16时40分26秒
     4 
     5 #include<vector>
     6 #include<list>
     7 #include<map>
     8 #include<set>
     9 #include<deque>
    10 #include<stack>
    11 #include<bitset>
    12 #include<algorithm>
    13 #include<functional>
    14 #include<numeric>
    15 #include<utility>
    16 #include<sstream>
    17 #include<iostream>
    18 #include<iomanip>
    19 #include<cstdio>
    20 #include<cmath>
    21 #include<cstdlib>
    22 #include<cstring>
    23 #include<ctime>
    24 #define LL long long
    25 #define maxn 300005
    26 using namespace std;
    27 int n , m; 
    28 struct node{  
    29     int l ,r , v; 
    30 }mp[maxn];
    31 LL dp[maxn];
    32 int mx[maxn];
    33 int mxc[maxn];
    34 int cmp(node a, node b)
    35 {
    36    return a.v < b.v ;
    37 }
    38 stack <int > si ;
    39 stack <LL > val ; 
    40 int main(){
    41    scanf("%d %d",&n,&m);
    42    for(int i= 1;i <= m;i++)
    43    {
    44       scanf("%d %d %d",&mp[i].l,&mp[i].r,&mp[i].v);
    45    }
    46    stable_sort(mp+1,mp+1+m,cmp);
    47 
    48    for(int i = 1;i <=m;)
    49    {
    50        LL tmpa,tmpb;
    51        int j ; 
    52        for(j = i ; mp[j].v == mp[i].v; j  ++)
    53           {
    54               si.push(mp[j].r);
    55               val.push(dp[mp[j].l]+1);
    56           }
    57        i = j;
    58        while(!si.empty())
    59        {
    60           int p = si.top();
    61           si.pop();
    62           LL vv = val.top();
    63           val.pop();
    64           dp[p] = max(vv,dp[p]);
    65        }
    66    }
    67    LL ans = 0 ; 
    68    for(int i = 1;i <= n;i ++)
    69    {
    70      ans = max(ans,dp[i]);
    71    }
    72    printf("%I64d
    ",ans);
    73 return 0;
    74 }
    View Code
    没有梦想,何谈远方
  • 相关阅读:
    软件工程 speedsnail 第二次冲刺2
    软件工程 speedsnail 第二次冲刺1次
    软件工程 speedsnail 冲刺9
    软件工程 speedsnail 冲刺8
    软件工程 speedsnail 冲刺7
    软件工程 speedsnail 冲刺6
    软件工程 speedsnail 冲刺5
    软件工程 speedsnail 冲刺4
    软件工程 speedsnail 冲刺3
    软件工程 speedsnail 冲刺2
  • 原文地址:https://www.cnblogs.com/zyue/p/4335923.html
Copyright © 2020-2023  润新知