首页 > 其他分享 >POJ 2442 Sequence

POJ 2442 Sequence

时间:2023-04-20 22:42:10浏览次数:53  
标签:2442 Sequence int sequence POJ each test line include


F -  Sequence


Time Limit:6000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u


Submit  Status  Practice  POJ 2442


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<stdio.h>
#include<string.h>
#include<iostream>
#include<queue>
#include<algorithm>

#define N 2101

using namespace std;



int main()
{
    int T,i,j,n,m;
    int a[N];
    scanf("%d",&T);
    while(T--)
    {
        int pp;
        priority_queue< int,vector<int>,greater<int> >q;
        priority_queue< int,vector<int>,less<int> >p;
        scanf("%d%d",&n,&m);
        for(i=0; i<m; i++)
        {
            scanf("%d",&pp);
            q.push(pp);
        }
        for(i=1; i<n; i++)
        {
            for(j=0; j<m; j++)
            {
                scanf("%d",&a[j]);
            }
            while(!q.empty())
            {
                int mm = q.top();
                q.pop();
                for(j=0; j<m; j++)
                {
                    if(p.size()<m)
                    {
                        p.push(mm+a[j]);
                    }
                    else if(p.size()==m && p.top()>mm+a[j])
                    {
                        p.pop();
                        p.push(mm+a[j]);
                    }
                }
            }
            while(!p.empty())
            {
                q.push(p.top());
                p.pop();
            }
        }
        for(i=0; i<m; i++)
        {
            if(i == 0)
            {
                printf("%d",q.top());
                q.pop();
            }
            else
            {
                printf(" %d",q.top());
                q.pop();
            }
        }
        printf("\n");
    }
    return 0;
}




标签:2442,Sequence,int,sequence,POJ,each,test,line,include
From: https://blog.51cto.com/u_14834528/6210798

相关文章

  • POJ3984 迷宫问题(BFS 记忆路径)
    迷宫问题TimeLimit:1000MS     MemoryLimit:65536KB     64bitIOFormat:%I64d&%I64uSubmit Status Practice POJ3984SystemCrawler (2014-09-11)Description定义一个二维数组: intmaze[5][5]={0,1,0,0......
  • POJ 1789 Truck History
    TruckHistoryTimeLimit:2000MS     MemoryLimit:65536KB     64bitIOFormat:%I64d&%I64uSubmit Status Practice POJ1789DescriptionAdvancedCargoMovement,Ltd.usestrucksofdifferenttypes.Sometrucksareused......
  • Common Subsequence
    CommonSubsequenceTimeLimit:1000MS MemoryLimit:10000KTotalSubmissions:43130 Accepted:17470DescriptionAsubsequenceofagivensequenceisthegivensequencewithsomeelements(possiblenone)leftout.GivenasequenceX=<x1,x2,.........
  • sequence (牛客多校) (区间包含某个值的最大最小, 和那个东西)
     思路:一步一步的拆解分析有一个min(al...r)通过这个东西那么就可以根据这个ai值分区间,可以通过单调zhai处理当然也可以去利用启发式合并处理,  在处理区间的时候,因为这个有正负,要分类讨论正就是最大负数就是最小遇到区间包含某个值的区间最大最小那么就......
  • POJ--3050 Hopscotch(暴搜)
    记录21:362023-4-16http://poj.org/problem?id=3050reference:《挑战程序设计竞赛(第2版)》第二章练习题索引p135DescriptionThecowsplaythechild'sgameofhopscotchinanon-traditionalway.Insteadofalinearsetofnumberedboxesintowhichtohop,thec......
  • AtCoder Regular Contest 104 F Visibility Sequence
    洛谷传送门AtCoder传送门考虑连边\((i,p_i)\)(若\(p_i=-1\)则不连边),可以发现形成了一篇内向树森林且这个森林存在一个dfs序为\(1,2,...,n\)。这棵森林有如下性质:\(\forallv\inson_u,h_u>h_v\)\(\forallv,w\inson_u\landv<w,h_v\leh_w\)考虑一个\(p......
  • kuangbin专题一 简单搜索 迷宫问题(POJ-3984)
    迷宫问题TimeLimit:1000MS MemoryLimit:65536KDescription定义一个二维数组:intmaze[5][5]={0,1,0,0,0,0,1,0,1,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,0,};它表示一个迷宫,其中的1表示墙壁,0表示可以走的路,只能横着走或竖着走,不能斜着走,要求编......
  • kuangbin专题一 简单搜索 罐子(POJ-3414)
    PotsTimeLimit:1000MS MemoryLimit:65536KDescriptionYouaregiventwopots,havingthevolumeofAandBlitersrespectively.Thefollowingoperationscanbeperformed:FILL(i)fillthepoti(1≤i≤2)fromthetap;DROP(i)emptythep......
  • poj2750(线段树+复杂区间合并)
    PottedFlowerPOJ-2750思路:我们将题目简单化,假设我们要求的是序列的最大连续子段和,且可以包括所有数。我们的线段树需要维护这段区间的最大前缀和pre,最大后缀和suf,区间和sum,区间连续最大和mx。那么难点就在于如何由子节点更新父节点。我们可以知道,tr[p].sum=tr[lc].sum......
  • Bracket Sequence
    #include<iostream>usingnamespacestd;#defineintlonglongconstintp=1e9+7;intquick(inta,intb,intp){intres=1;while(b){if(b&1)res=res*a%p;a=a*a%p;b>>=1;}returnres;}intc(inta,int......