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

  • 相关阅读:
    2016-7-4工作总结
    2016-7第一周工作总结
    2016-6-30 工作总结
    2016-6-29 工作总结
    2016-6-28 工作总结
    基于软件开发对嵌入式开发的思考
    团队项目总结
    软件工程课程总结
    图描述之:流程图
    004-二叉树的遍历
  • 原文地址:https://www.cnblogs.com/lz87/p/15824698.html
Copyright © 2020-2023  润新知