• [CodeForces] Dirty Deeds Done Dirt Cheap Review


    Problem

    First I thought about modelling this problem as a directed graph, where between each pair of nodes, an edge represents a valid < > or > < transition. Then do a dfs with dp to compute the longest valid path. But there can be as many as O(N^2) edges.

    By drawing some examples, I made the following observations:

    1. there are 2 types of integer pairs, either (a > b) or (a < b).

    2. we will never mix these 2 types together in any valid path. For (a < b), the next pair must be (c, d) such that b > c,  c < d. So we separate these 2 types and consider them separately.

    3. For each type, greedy works: For type a < b, pick max(b) first; for type a > b, pick min(b) first. Doing this allows us to use all pairs of the same type. 

    Proof: For type a < b, say we have (L1, R1), (L2, R2), (L3, R3), without the loss of generality, let's assume R1 > R2 > R3. So R1 is the max, R2 is the second max and R3 is the third max and we have R1 > R2 > L2, R2 > R3 > L3, we can connect all 3 pairs in this order.

  • 相关阅读:
    brctl 使用说明
    Flash文件系统介绍和平台采用squashfs+ubifs原因
    xargs
    svn的常用命令
    shell中的if用法
    shell中单双引号
    删除文件中的 ^M 字符
    博客园添加live2d看板娘
    IOS 自定义转场动画
    rails
  • 原文地址:https://www.cnblogs.com/lz87/p/15824698.html
Copyright © 2020-2023  润新知