当前位置:网站首页>(more than 2022 cattle school four) A - Task Computing + dynamic programming (sort)
(more than 2022 cattle school four) A - Task Computing + dynamic programming (sort)
2022-08-01 04:48:00 【AC__dream】
Title: 
Sample input:
5 21 2 3 4 512000 11000 10000 9000 8000Sample output:
8.5000000000000000The meaning of the question: select m (a1,a2,...,am) from n tasks and sort them arbitrarily, the income is 
Seek maximum profit.
Seeing the subscript distribution of the formula, we know that this value is related to the order of the tasks, so we should first consider what order to sort in. The common method is the gradual adjustment method, that is, Assume an order first, then exchange the positions of two adjacent elements, calculate the answers corresponding to the two sorting methods, and compare them to know what to sort by!
The following is the adjustment process:

We first sort the n tasks according to the above method, then m randomly selected from them all satisfy the above sorting rules, so the problem becomes how do we select m tasks from the n tasks.
What I thought at first was to use f[i][j] to represent the maximum value that can be obtained by selecting j tasks from the first i tasks, and then use a mul[i][j] to represent the value of f[i][j] state, then the recursion equation is:
f[i][j]=max(f[i-1][j],f[i-1][j-1]+w[i]*mul[i-1][j-1]), then update the mul array
But then I found out that this is a problem, because the maximum value we can get by selecting j tasks from the first i tasks is not necessarily the selection of j-1 tasks or j tasks from the first i-1 tasks.The maximum value obtained by the task, because the number of tasks selected from the first i-1 tasks will directly affect the product of the selected tasks, so this will have a great impact on the answer, so it cannot be done.
Positive solution:

The reason why the dynamic transition equation we just considered does not work is because The latter value depends on the previous two values, one is the product and the other is the sumformula, so we can't transfer backward directly according to the value of the sum formula, but after the deformation of the above formula, we can clearly find that we can deduce from the back to the front, so that the previous value is only followed byThe latter sum is related to the formula, not the product, so that we can perform dynamic transfer, but the update method will change slightly. This method is quite wonderful.
Let f[i][j] represent the maximum value of j tasks selected by considering the i~n tasks, then we directly update the array in reverse order
Dynamic transfer equation:f[i][j]=max(f[i+1][j],f[i+1][j-1]*p[i].q+p[i].w)
Here is the code:
#include#include#include#include#include 边栏推荐
- Dry goods!How to Construct SRv6-TE Performance Test Environment Using Instrumentation
- 博客系统(完整版)
- PMP 80个输入输出总结
- This article takes you to understand the past and present of Mimir, Grafana's latest open source project
- leetcode:126. Word Solitaire II
- 阿叶的目标
- 数组问题之《两数之和》以及《三数之和 》
- 2022-07-31: Given a graph with n points and m directed edges, you can use magic to turn directed edges into undirected edges, such as directed edges from A to B, with a weight of 7.After casting the m
- The Flow Of Percona Toolkit pt-table-checksum
- 初识shell脚本
猜你喜欢
随机推荐
"ArchSummit: The cry of the times, technical people can hear"
leetcode:126. Word Solitaire II
typescript27 - what about enumeration types
typescript20-接口
最新 955 不加班的公司名单
高数 | 【重积分】线面积分880例题
MySQL4
请问shake数据库中为什么读取100个collection 后,直接就退出了,不继续读了呢?
状态压缩dp
IJCAI2022 | Hybrid Probabilistic Reasoning with Algebraic and Logical Constraints
SQL Analysis of ShardingSphere
JS new fun(); class and instance JS is based on object language Can only act as a class by writing constructors
Pyspark Machine Learning: Vectors and Common Operations
Simulation of Active anti-islanding-AFD Active Anti-islanding Model Based on Simulink
PMP子过程定义总结
产品经理访谈 | 第五代验证码的创新与背景
PMP 项目质量管理
【无标题】
【云原生之kubernetes实战】kubernetes集群的检测工具——popeye
UE4 模型OnClick事件不生效的两种原因









