• [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.

  • 相关阅读:
    windows2016优化
    oracle什么时候需要commit
    Mysql的锁表,锁行记录
    git add
    linux系统优化
    解决rsyslog启动问题
    HAProxy启用日志功能
    nc命令获取远端端口状态
    将pip源更换到国内镜像
    Centos7.6下安装Python3.7
  • 原文地址:https://www.cnblogs.com/lz87/p/15824698.html
Copyright © 2020-2023  润新知