Description

Given m sequences, each contains n non-negative integer. Now we may select one number from each sequence to form a sequence with m integers. It's clear that we may get n ^ m this kind of sequences. Then we can calculate the sum of numbers in each sequence, and get n ^ m values. What we need is the smallest n sums. Could you help us?

Input

The first line is an integer T, which shows the number of test cases, and then T test cases follow. The first line of each case contains two integers m, n (0 < m <= 100, 0 < n <= 2000). The following m lines indicate the m sequence respectively. No integer in the sequence is greater than 10000.

Output

For each test case, print a line with the smallest n sums in increasing order, which is separated by a space.

Sample Input

1
2 3
1 2 3
2 2 3

Sample Output

3 3 4
 #include"iostream"
#include"algorithm"
#include"ctime"
#include"cstdio"
#include"cctype"
using namespace std;
#define maxx 2008
int a[maxx],b[maxx],sum[maxx];
int main()
{
int i,j,k,t,n,m,temp;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&m,&n);
for(i=;i<n;i++)
scanf("%d",&a[i]);
for(i=;i<m;i++)
{
sort(a,a+n);
for(j=;j<n;j++)
scanf("%d",&b[j]);
for(j=;j<n;j++)
sum[j]=a[j]+b[];
make_heap(sum,sum+n);
for(j=;j<n;j++)
for(k=;k<n;k++)
{
temp=b[j]+a[k];
if(temp>=sum[])
break;
pop_heap(sum,sum+n);
sum[n-]=temp;
push_heap(sum,sum+n);
}
for(j=;j<n;j++)
a[j]=sum[j];
}
sort(a,a+n);
printf("%d",a[]);
for(j=;j<n;j++)
printf(" %d",a[j]);
printf("\n");
printf("time :%d\n",clock());
}
return ;
}

Sequence用堆排序的更多相关文章

  1. 1306.Sequence Median(堆排序)

    1306 URAL真是没水题 以为简单的排序就好了 ME  内存限制很紧 堆排序 或者 STL 用堆排序做的 正好复习一下 都忘了 #include <iostream> #include ...

  2. 《Algorithms 4th Edition》读书笔记——2.4 优先队列(priority queue)-Ⅶ(延伸:堆排序的实现)

    2.4.5 堆排序 我们可以把任意优先队列变成一种排序方法.将所有元素插入一个查找最小元素的有限队列,然后再重复调用删除最小元素的操作来将他们按顺序删去.用无序数组实现的优先队列这么做相当于进行一次插 ...

  3. PAT A1098 Insertion or Heap Sort (25 分)——堆排序和插入排序,未完待续。。

    According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and gr ...

  4. PAT甲级——1098 Insertion or Heap Sort (插入排序、堆排序)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90941941 1098 Insertion or Heap So ...

  5. PAT Advanced 1098 Insertion or Heap Sort (25) [heap sort(堆排序)]

    题目 According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and ...

  6. 算法与数据结构(十四) 堆排序 (Swift 3.0版)

    上篇博客主要讲了冒泡排序.插入排序.希尔排序以及选择排序.本篇博客就来讲一下堆排序(Heap Sort).看到堆排序这个名字我们就应该知道这种排序方式的特点,就是利用堆来讲我们的序列进行排序.&quo ...

  7. [数据结构]——堆(Heap)、堆排序和TopK

    堆(heap),是一种特殊的数据结构.之所以特殊,因为堆的形象化是一个棵完全二叉树,并且满足任意节点始终不大于(或者不小于)左右子节点(有别于二叉搜索树Binary Search Tree).其中,前 ...

  8. oracle SEQUENCE 创建, 修改,删除

    oracle创建序列化: CREATE SEQUENCE seq_itv_collection            INCREMENT BY 1  -- 每次加几个              STA ...

  9. Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等

    功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...

随机推荐

  1. JavaEE5 Tutorial_JavaBean,JSTL

    <jsp:useBean id="beanName" class="fully_qualified_classname" scope="scop ...

  2. 微信分享,使用js,分享给朋友,朋友圈,QQ微博

    <script> var imgUrl = "http://www.baidu.com/img/bdlogo.gif"; var lineLink = "ht ...

  3. Machine Learning & Data Mining 资料整合

    机器学习常见算法分类汇总 | 码农网 数据挖掘十大经典算法 | CSDN博客 (内含十个算法具体介绍) 支持向量机通俗导论(理解 SVM 的三层境界)| CSDN博客 (强烈推荐关注博主) 教你如何迅 ...

  4. Spark Streaming 架构

    图 1   Spark Streaming 架构图 组件介绍:‰ Network Input Tracker : 通 过 接 收 器 接 收 流 数 据, 并 将 流 数 据 映 射 为 输 入DSt ...

  5. homework -06 围棋

    playPrev功能的实现 public void playPrev(ref GoMove gm) { Point p = gm.Point; m_colorToPlay = gm.Color; cl ...

  6. 从 ALAsset 中取出属性

    #pragma mark - 从相册数组中取出所有的 图片数据 -(NSMutableArray *)getImageFromAlbumArray:(NSArray *)albumArr { NSMu ...

  7. Codeforces Round #353 (Div. 2) D. Tree Construction (二分,stl_set)

    题目链接:http://codeforces.com/problemset/problem/675/D 给你一个如题的二叉树,让你求出每个节点的父节点是多少. 用set来存储每个数,遍历到a[i]的时 ...

  8. MyBatis中井号与美元符号的区别

    #{变量名}可以进行预编译.类型匹配等操作,#{变量名}会转化为jdbc的类型. select * from tablename where id = #{id} 假设id的值为12,其中如果数据库字 ...

  9. eclipse 安装scons

    http://www.sconsolidator.com/update  Installation To use SConsolidator, you first have to install SC ...

  10. velocity 快速入门

    基本语法      1.变量定义 : $name 注意 : a.名字和$配合一起用  b.更规范的写法是 ${name} 2.赋值 : #set($name = "威少") 3.条 ...