当前位置:网站首页>最大化平均值
最大化平均值
2022-07-29 16:43:00 【51CTO】
有n个物品的重量和价值分别是Wi和Vi,从中选出K个物品使得单位重量的价值最大。
最大化平均值的经典,一般最先想到可能的方法是按照单位价值排序,从大到小的进行选取,但是这个方法对于下面一组例子来说:
n=3; k=2; (w,v)=(2,2),(5,3),(2,1);则可能得出的结果是5/7=0.714,所以这个方法是要排除的,那么如何想到最大化平均值这个方向呢?实际上,对于这个问题我们可以使用二分搜索法解决,我们定义:
条件get(mid):=可以选择使得单位重量的价值不小于mid
因此,原问题就变成了求满足get(mid)的最大mid,那么如何判断get(mid)是否可行?假设我们选了某个物品的集合S()那么它们的单位重量的价值是;定义sum(v)为v的值的和
sum(Vi(i属于S))/sum(Wi(i属于S));因此就变成了判断是否存在mid满足以下条件:sum(Vi(i属于S))/sum(Wi(i属于S))>=mid;变形得到:sum(Vi-mid*Wi)>=0,因此对此式的值进行贪心选取,进一步求sum(Vi-mid*Wi)从大到小排列中前k个的和不小于零,每次判断的复杂度为O(n*log(n))
实现:
边栏推荐
- Interviewer: How does MySQL tune SQL statements based on execution plans?
- Knowledge map construction whole process
- HER2-2-ME-BSANPs单抗特异性的2-甲氧基雌二醇白蛋白纳米粒的研究与制备
- Turbine Aggregation Monitoring
- Chicken and rabbit in the same cage
- 闻泰科技拟收购欧菲光摄像头业务资产,或将进入苹果供应链!
- mysql的sql分页查询语句怎么写_sql 分页查询语句(mysql分页语句)「建议收藏」
- ASCII code sorting
- Database Project 01 Documentation: Database Skills Needed for Software Testing
- 面试官:MySQL如何根据执行计划调优SQL语句?
猜你喜欢

Query term weights, search term weighting

阅读顺序

leetcode:1901. 寻找峰值 II【二分找矩阵局部最大】

Tech Talk 活动回顾|基于 Amazon KVS 打造智能视觉产品

Thread Dump分析方法

What is the GMAT test?

This article penetrates the architecture design and cluster construction of the distributed storage system Ceph (hands-on)

HER2-2-ME-BSANPs单抗特异性的2-甲氧基雌二醇白蛋白纳米粒的研究与制备

Nuggets quantification: Obtain data through the history method, and use the same proportional weighting factor as Sina Finance and Snowball.different from a flush

(笔记)Build was configured to prefer settings repositories over project repositories but 解决方法
随机推荐
js选择多张图片对比功能插件
[C语言刷题篇]链表运用讲解
[C language brush questions] Explanation of the use of linked lists
知识图谱构建全流程
闻泰科技拟收购欧菲光摄像头业务资产,或将进入苹果供应链!
LinkedList 5-141. The circular linked list
CRM如何帮助企业营销获客
Groeb - "gramm, explicit and complete n -" gramm mask language model, implements the explicit n - "gramm semantic unit modeling knowledge.
大规模线上应用TiDB会遇到的坑,本文都帮你排除好了
Ernie-gram, 显式、完备的 n-gram 掩码语言模型,实现了显式的 n-gram 语义单元知识建模。
【翻译】设备管理器—英特尔网卡属性设置高级选项的功能
SR-TE的功能架构概述
[WeChat Mini Program] Component usage and attribute reference
This article penetrates the architecture design and cluster construction of the distributed storage system Ceph (hands-on)
tutorial/detailed_workflow.ipynb 量化金融Qlib库
再见Postman!一款更适合国人的接口管理工具
[High Concurrency] I used multithreading to further optimize the massive data proofreading system under the billion-level traffic e-commerce business, and the performance has been improved by 200% aga
【Leetcode】200. 岛屿数量(中等)
The difference between Loadrunner and Jmeter is the same
Sentinel热门词汇限流如何实现