博客
关于我
B. Polycarp's Practice
阅读量:598 次
发布时间:2019-03-09

本文共 2065 字,大约阅读时间需要 6 分钟。

Polycarp's practice problem can be solved efficiently by determining the optimal distribution of problems into days to maximize the total profit. Here's a structured approach to understand and solve the problem:

  • Problem Constraints and Intuition:

    • Polycarp needs to solve n problems over k days.
    • Each day, he must solve a contiguous sequence of problems from his list.
    • The profit for each day is the maximum difficulty in the solved sequence.
    • The goal is to maximize the sum of these daily profits.
  • Key Insight:

    • To maximize the total profit, we should prioritize solving the most difficult problems on separate days. This is because the maximum in each day's subset contributes directly to the total profit.
  • Algorithm Selection:

    • Sort the array of problem difficulties in descending order.
    • Select the top k elements as the daily maxima.
    • These top k values will be the maximums for each day, contributing the most to the total profit.
  • Daily Distribution Strategy:

    • After sorting the array, the largest k elements will be the daily profit contributors.
    • Distribute these elements such that each is the maximum of a contiguous segment, starting from the left of the array.
  • Implementation Steps:

    • Read input values for n, k, and the array a.
    • Sort a in descending order.
    • Sum the top k elements to get the maximum total profit.
    • Record the indices of these top k elements, ensuring they are distributed to form contiguous segments for each day.
  • Edge Cases:

    • When k equals n, every day is a single problem, and the total profit is the sum of all elements.
    • When all elements are the same, the profit is simply k times the value.
    • When the largest elements are clustered, their positions must be carefully recorded to form valid contiguous segments.
  • Output:

    • Print the total maximum profit.
    • Print the distribution of problems into days, ensuring each day's segment is contiguous and correctly sequences the sorted top k elements.
  • By following these steps, we ensure that the solution is both optimal and efficient, achieving the maximum possible total profit for Polycarp's practice.

    转载地址:http://wbhpz.baihongyu.com/

    你可能感兴趣的文章
    Qt笔记——获取位置信息的相关函数
    查看>>
    POJ 2484 A Funny Game(神题!)
    查看>>
    POJ 2486 树形dp
    查看>>
    POJ 2488:A Knight's Journey
    查看>>
    SpringBoot为什么易学难精?
    查看>>
    poj 2545 Hamming Problem
    查看>>
    poj 2723
    查看>>
    poj 2763 Housewife Wind
    查看>>
    Qt笔记——模型/视图MVD 文件目录浏览器软件
    查看>>
    POJ 2892 Tunnel Warfare(树状数组+二分)
    查看>>
    poj 2965 The Pilots Brothers' refrigerator-1
    查看>>
    poj 3026( Borg Maze BFS + Prim)
    查看>>
    POJ 3041 - 最大二分匹配
    查看>>
    POJ 3041 Asteroids(二分匹配模板题)
    查看>>
    Qt笔记——标准文件对话框QFileDialog
    查看>>
    poj 3083 Children of the Candy Corn
    查看>>
    POJ 3083 Children of the Candy Corn 解题报告
    查看>>
    POJ 3253 Fence Repair C++ STL multiset 可解 (同51nod 1117 聪明的木匠)
    查看>>
    Qt笔记——控件总结
    查看>>
    poj 3262 Protecting the Flowers 贪心
    查看>>