当前位置:网站首页>(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 8000
Sample output:
8.5000000000000000
The 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
边栏推荐
- scheduleWithFixedDelay和scheduleAtFixedRate的区别
- 风险策略调优中重要的三步分析法
- Typescript20 - interface
- 产品经理访谈 | 第五代验证码的创新与背景
- 开源许可证 GPL、BSD、MIT、Mozilla、Apache和LGPL的区别
- 【愚公系列】2022年07月 .NET架构班 085-微服务专题 Abp vNext微服务网关
- 高数 | 【重积分】线面积分880例题
- Flutter Tutorial 01 Configure the environment and run the demo program (tutorial includes source code)
- typescript23-元组
- 「以云为核,无感极速」顶象第五代验证码
猜你喜欢
[kali-information collection] enumeration - DNS enumeration: DNSenum, fierce
typescript28-枚举类型的值以及数据枚举
"ArchSummit: The cry of the times, technical people can hear"
MySQL3
出现Command ‘vim‘ is available in the following places,vim: command not found等解决方法
微软 Win10 照片磁贴后的又一“刺客”,谷歌 Chrome 浏览器将在新标签页展示用户照片
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
Message Queuing Message Storage Design (Architecture Camp Module 8 Jobs)
Pyspark机器学习:向量及其常用操作
typescript21 - Comparison of Interfaces and Type Aliases
随机推荐
Flink 1.13 (8) CDC
The method of solving stored procedure table name passing through variable in mysql
Excel record of integer programming optimization model to solve the problem
万字逐行解析与实现Transformer,并进行德译英实战(二)
UE4 从鼠标位置射出射线检测
56:第五章:开发admin管理服务:9:开发【文件上传到,MongoDB的GridFS中,接口】;(把文件上传到GridFS的SOP)
[kali-information collection] enumeration - DNS enumeration: DNSenum, fierce
SQL Analysis of ShardingSphere
MySQL3
时时刻刻保持敬畏之心
typescript22-接口继承
最新 955 不加班的公司名单
typescript25 - type assertion
TypeScript simplifies running ts-node
博客系统(完整版)
Interview Blitz 69: Is TCP Reliable?Why?
The Flow Of Percona Toolkit pt-table-checksum
TIM登陆时提示00001(TIM00001)
PMP 项目质量管理
A way to deal with infinite debugger