正解:堆

解题报告:

传送门$QwQ$

全场除了我都切了系列$kk$

首先看$n=2$的情况.

首先暴力不说?就记录一个$sum$再分别记录$xy$两维的下标存到堆里面每次取队头并继续扩展就完事$QwQ$.

然后发现会枚举重复,就不太优秀,考虑优化$QwQ$.

于是考虑记录下这个点是扩展$x$的时候扩展来的还是扩展$y$的时候扩展来的,如果是扩展$x$的时候扩展来的就只扩展$x$了,否则就$xy$都要扩展.

这样就能保证每个状态只会被扩展一次了.

然后现在考虑$n>2$的情况.

就直接当$n=2$地做$n-1$次就完事

然后这个复杂度是$O(nmlogm)$的.

优化康考试总结$QwQ$,$over$

#include<algorithm>
#include<iostream>
#include<iomanip>
#include<vector>
#include<cstdio>
#include<queue>
using namespace std;
#define il inline
#define gc getchar()
#define ri register int
#define rb register bool
#define rc register char
#define rp(i,x,y) for(ri i=x;i<=y;++i)
#define my(i,x,y) for(ri i=x;i>=y;--i) const int N=1e5+;
int n,m,as;
vector<int>V[N],v;
struct node{int sum,fr,nwx,nwy;};
priority_queue<node>Q; il int read()
{
ri x=;rb y=;rc ch=gc;
while(ch!='-' && (ch>'' || ch<''))ch=gc;
if(ch=='-')y=,ch=gc;
while(ch>='' && ch<='')x=(x<<)+(x<<)+(ch^''),ch=gc;
return y?x:-x;
}
il bool cmp(ri gd,ri gs){return gd>gs;}
il bool operator < (node gd,node gs){return gd.sum>gs.sum;}
il void work(ri x,ri y)
{
ri szx=V[x].size(),szy=V[y].size();
while(Q.size())Q.pop();;v.clear();Q.push((node){V[x][]+V[y][],,,});
rp(i,,m)
{
node nw=Q.top();Q.pop();v.push_back(nw.sum);
if(nw.nwx+<szx)Q.push((node){nw.sum-V[x][nw.nwx]+V[x][nw.nwx+],,nw.nwx+,nw.nwy});
if(nw.fr)continue;
if(nw.nwy+<szy)Q.push((node){nw.sum-V[y][nw.nwy]+V[y][nw.nwy+],,nw.nwx,nw.nwy+});
}
V[y]=v;
} int main()
{
//freopen("2442.in","r",stdin);//freopen("2442.out","w",stdout);
ri T=read();
while(T--)
{
n=read();m=read();as=;
rp(i,,n){V[i].clear();rp(j,,m)V[i].push_back(read());sort(V[i].begin(),V[i].end());}
rp(i,,n)work(i-,i);rp(i,,m-)printf("%d ",V[n][i]);printf("\n");
}
return ;
}

随机推荐

  1. @codechef - SONATR@ Sonya and Tree

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定 p 为 0~N-1 的一个排列,并给定一棵 N 个点的树. ...

  2. protobuf_1

    我使用的是最新版本的protobuf(protobuf-2.6.1),编程工具使用VS2010.简单介绍下google protobuf: google protobuf 主要用于通讯,是google ...

  3. linux自动挂载NTFS格式移动硬盘

    转自:http://blog.163.com/cmh_lj/blog/static/100812304201252522119264/ 由于移动硬盘还有不少的资料,刚插入移动硬盘的时候发现只能自动挂载 ...

  4. poj 3278(hdu 2717) Catch That Cow(bfs)

    Catch That Cow Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  5. Codeforces Round #168 (Div. 1 + Div. 2)

    A. Lights Out 模拟. B. Convex Shape 考虑每个黑色格子作为起点,拐弯次数为0的格子构成十字形,拐弯1次的则是从这些格子出发直走达到的点,显然需要遍历到所有黑色黑色格子. ...

  6. Spring Boot版本,Spring Cloud版本与组件版本关系

    我们在学习Spring Cloud时,可能总是碰到以下问题: 1.Spring Boot版本与Spring Cloud版本关系 2.启动时,报莫名其妙的错,稀里糊涂的换个版本就好了 3.这么多版本,用 ...

  7. Python--day65--母版和继承的基本使用

  8. tf.contrib.learn.preprocessing.VocabularyProcessor()

    tf.contrib.learn.preprocessing.VocabularyProcessor (max_document_length, min_frequency=0, vocabulary ...

  9. H3C根桥的选举

  10. Linux 内核同步 urb

    不幸的是, 同步 urb 没有一个象中断, 控制, 和块 urb 的初始化函数. 因此它们必须在 驱动中"手动"初始化, 在它们可被提交给 USB 核心之前. 下面是一个如何正确初 ...