CareerCup Find top k values (asec) which can either be the number from the array A

本文探讨了一种算法问题,即从一个已排序的整数数组中找出最大的K个数值组合,这些组合可以是数组中的单一元素、任意两元素之和或三元素之和。文章进一步介绍了如何通过构建三个不同的堆来分别存储单个元素、两个元素的组合及三个元素的组合,最终将这三个堆合并得到所需的前K大的数值。
You are given an array A of k values which contain int values in sorted (asec) order. Find top k values (asec) which can either be the number from the array A, or sum of any two numbers from A or sum of any three numbers from A. So, if A's values are represented as : a1,a2,...,ak , the possible numbers can be: a(i), a(i)+a(j), a(i)+a(j)+a(l) for any i,j,l < k 

Ex: A[7] = {3,4,5,15,19,20,25} 

output B[7] = {3,4,5,(3+4),(3+5),(4+5),(3+4+5)}

-------------------------------------------------


Get the first k values from A , then name as heap1

Get the first k values from sum of any two numbers from A, then name as heap2

Get the first k values from sum of any three numbers from A, then name as heap3

Merge heap1, heap2, heap3






评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值