博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
U - stl 的 优先队列 Ⅰ
阅读量:7144 次
发布时间:2019-06-29

本文共 1455 字,大约阅读时间需要 4 分钟。

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

12 31 2 32 2 3

Sample Output

3 3 4
#include
#include
#include
#include
using namespace std;int a[105][2005],b[2005];priority_queue
p;int main() { int T; scanf("%d",&T); while(T--){ int n ,m; scanf("%d%d",&m,&n); //m个序列,每个含n个数字 for(int i=0;i
=0;t--){ if(j==0)p.push(a[i][0]+b[t]); //将第i个序列的第一项与加之i-1序列的前n小项相加 else{ if(p.top()>b[t]+a[i][j]){ p.pop(); p.push(a[i][j]+b[t]); } else break; } } } } for(int i=0;i
=0;i--){ if(i==0)printf("%d\n",b[i]); else printf("%d ",b[i]); } } //system("pause"); return 0;}

 

转载地址:http://hywgl.baihongyu.com/

你可能感兴趣的文章
老司机避坑指南:如何快速搞定微服务架构?
查看>>
杨老师课堂之JavaScript案例全选、全不选、及反选
查看>>
开源编辑器 Atom 简化代码审查过程
查看>>
等等!这两个mysql慢查询的坑我已经替你们踩了
查看>>
【Python标准库:fileinput】优雅的读取文件
查看>>
“NO GENDER.NO BORDER.”,无性别服饰品牌“Bosie”获近千万元Pre-A轮融资
查看>>
用Python统计你的简书数据
查看>>
全票通过,百度 Doris 项目进入 Apache 基金会孵化器
查看>>
Retrofit2源码解析——网络调用流程(下)
查看>>
5G时代下的移动边缘计算(MEC)探索系列之二
查看>>
白衣天使要承包你的周末咯!快来3小时公益平台!
查看>>
用GitHub Issue取代多说,是不是很厉害?
查看>>
3 个实例带您了解如何快速迁移旧版的 Windows 应用程序
查看>>
第15天,JavaScript之事件介绍
查看>>
去除mysql 大小写敏感
查看>>
find: 路径必须在表达式之前:
查看>>
hanlp自然语言处理包的基本使用--python
查看>>
Linux网络协议栈(三)——网络设备(2)
查看>>
MAC下尝试PHP7 alpha版本的安装
查看>>
Laravel(1) 注册重写
查看>>