(Application of heap) POJ 2442

Source: Internet
Author: User

Sequence
Time Limit: 6000MS Memory Limit: 65536K
Total Submissions: 7762 Accepted: 2565

Description

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

Input

The first line is a integer T, which shows the number of test cases, and then T test cases follow. The first line of each case contains integers m, n (0 < M <=, 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

Source

POJ Monthly,guang Lin
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <string > #include <algorithm> #include <cstdlib> #include <queue> #include <vector> #include <    Stack>using namespace Std;int tt,m,n;int a[2010],b[2010],heap[2010];int main () {scanf ("%d", &AMP;TT);        while (tt--) {scanf ("%d%d", &m,&n);        for (int i=0;i<n;i++) scanf ("%d", &a[i]);        Sort (a,a+n);        m--;            while (m--) {for (int i=0;i<n;i++) scanf ("%d", &b[i]);            Sort (b,b+n);            for (int i=0;i<n;i++) heap[i]=a[i]+b[0];            Make_heap (Heap,heap+n);                for (int i=1;i<n;i++) {bool ok=0;                    for (int j=0;j<n;j++) {int temp=a[j]+b[i];                       if (Temp

  

(Application of heap) POJ 2442

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.