博客
关于我
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/

    你可能感兴趣的文章
    php编写TCP服务端和客户端程序
    查看>>
    php编码规范
    查看>>
    PHP编码规范-PSR1、psr2 /psr3 psr4
    查看>>
    PHP编程效率的20个要点
    查看>>
    PHP网页缓存技术优点及代码
    查看>>
    PHP自动化测试(一)make test 和 phpt
    查看>>
    php自定义函数: 文件大小转换成智能形式
    查看>>
    php英语单词,php常用英语单词,快速学习php编程英语(6)
    查看>>
    R3.4.0安装包时报错“需要TRUE/FALSE值的地方不可以用缺少值”,需升级到R3.5.0
    查看>>
    PHP获取curl传输进度
    查看>>
    PHP获取IP所在地区(转)
    查看>>
    PHP获取IP的方法对比
    查看>>
    php获取json里面内容
    查看>>
    R2的版本由来
    查看>>
    PHP获取图片宽度高度、大小尺寸、图片类型、用于布局的img属性
    查看>>
    PHP获取当前文件的绝对路径
    查看>>
    PHP获取当前时间、时间戳的各种格式写法汇总
    查看>>
    PHP获取当前页面的完整URL
    查看>>
    php获取数据库中数据生成json,中文乱码问题的解决方案
    查看>>
    php获取文件夹中文件的两种方法
    查看>>