题目链接

Problem Description

As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:

Yuta has n positive A1−An and their sum is m. Then for each subset S of A, Yuta calculates the sum of S.

Now, Yuta has got 2n numbers between [0,m]. For each i∈[0,m], he counts the number of is he got as Bi.

Yuta shows Rikka the array Bi and he wants Rikka to restore A1−An.

It is too difficult for Rikka. Can you help her?

Input

The first line contains a number t(1≤t≤70), the number of the testcases.

For each testcase, the first line contains two numbers n,m(1≤n≤50,1≤m≤104).

The second line contains m+1 numbers B0−Bm(0≤Bi≤2n).

Output

For each testcase, print a single line with n numbers A1−An.

It is guaranteed that there exists at least one solution. And if there are different solutions, print the lexicographic minimum one.

Sample Input

2

2 3

1 1 1 1

3 3

1 3 3 1

Sample Output

1 2

1 1 1

Hint

In the first sample, \(A\) is \([1,2]\). \(A\) has four subsets \([],[1],[2],[1,2]\) and the sums of each subset are \(0,1,2,3\). So \(B=[1,1,1,1]\)

题意:

给定数组b,保存的数组a中的所有子集和的个数,让找个这个数组a,并且按照字典序输出来。

分析:

b数组里面除了第一个元素b[0]肯定为1之外(表示空集的个数有且仅有一个),其余的第一次出现的b[i]==j(j!=0),那么就表示i这个数字肯定在a数组中存在,而且为第一个并且为最小的元素,同时将这个数的个数减减(相当于减去单独自己本身一个自己的情况),记录下标i。

这样循环的往后加b数组的元素下标偏移i个单位,如果此时两个数的个数均不为0,也就意味这后面的那个数,可以由前面这个数构成,然后让当前下标的数减去b[i],得到的那个数减去b[i]的个数,(相当于减去这个数可以由b[i]组合而成的个数)剩下的肯定就是这个数字本身的个数

就这样循环着往下找

代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std; const int maxm = 1100002;
int b[maxm];
int m;
int a[maxm]; int main()
{
int t;
scanf( "%d", &t );
while( t-- )
{
int n;
scanf( "%d%d", &n, &m );
for( int i = 0; i <= m; i++ )
{
scanf( "%d", b+i );
}
b[0] = 0;///空集的情况,不用任何的元素构成,将其赋值为0,不影响后面的计算
for( int i = 0; i < n; i++ )///循环得到a数组中的第i个元素
{
int j;
for( j = 0; j <= m; j++ )///找到当前的第一个不为0的
{
if( b[j] ) break;
}
b[j]--;///相当于有一个本身构成的元素
a[i] = j;///那么就肯定有一个这个元素,而且为当前的最小值
for( int k = j; k <= m; k++ )///找后面的所有可以由j组合而成的是数
{
if( k+j <= m && b[k] && b[k+j] )
{
b[k+j] -= b[k];
}
}
}
for( int i = 0; i < n; i++ )
{
i == 0 ? printf( "%d", a[i] ) : printf( " %d", a[i] );
}
printf( "\n" );
}
return 0;
}

2017 ACM暑期多校联合训练 - Team 5 1008 HDU 6092 Rikka with Subset (找规律)的更多相关文章

  1. 2017 ACM暑期多校联合训练 - Team 9 1008 HDU 6168 Numbers (模拟)

    题目链接 Problem Description zk has n numbers a1,a2,...,an. For each (i,j) satisfying 1≤i<j≤n, zk gen ...

  2. 2017 ACM暑期多校联合训练 - Team 3 1008 HDU 6063 RXD and math (莫比乌斯函数)

    题目链接 Problem Description RXD is a good mathematician. One day he wants to calculate: ∑i=1nkμ2(i)×⌊nk ...

  3. 2017 ACM暑期多校联合训练 - Team 4 1007 HDU 6073 Matching In Multiplication (模拟)

    题目链接 Problem Description In the mathematical discipline of graph theory, a bipartite graph is a grap ...

  4. 2017 ACM暑期多校联合训练 - Team 4 1012 HDU 6078 Wavel Sequence (模拟)

    题目链接 Problem Description Have you ever seen the wave? It's a wonderful view of nature. Little Q is a ...

  5. 2017ACM暑期多校联合训练 - Team 7 1010 HDU 6129 Just do it (找规律)

    题目链接 Problem Description There is a nonnegative integer sequence a1...n of length n. HazelFan wants ...

  6. 2017ACM暑期多校联合训练 - Team 2 1006 HDU 6050 Funny Function (找规律 矩阵快速幂)

    题目链接 Problem Description Function Fx,ysatisfies: For given integers N and M,calculate Fm,1 modulo 1e ...

  7. 2017ACM暑期多校联合训练 - Team 8 1008 HDU 6140 Hybrid Crystals (模拟)

    题目链接 Problem Description Kyber crystals, also called the living crystal or simply the kyber, and kno ...

  8. 2017ACM暑期多校联合训练 - Team 7 1008 HDU 6127 Hard challenge (极角排序)

    题目链接 Problem Description There are n points on the plane, and the ith points has a value vali, and i ...

  9. 2017ACM暑期多校联合训练 - Team 6 1008 HDU 6103 Kirinriki (模拟 尺取法)

    题目链接 Problem Description We define the distance of two strings A and B with same length n is disA,B= ...

随机推荐

  1. exce族函数详解

    exec函数族 函数族说明 fork() 函数用于创建一个新的子进程,该子进程几乎复制了父进程的全部内容,但是,这个新创建的子进程如何执行呢?exec 函数族就提供了一个在进程中启动另一个程序执行的方 ...

  2. Linux架设DDNS服务器之自动更新脚本

    问题描述:客户端是动态IP,每次连网之后要nsupdate下才可以把客户端的hostname 与IP映射更新到DNS Server上 命令如下: nsupdate -k K*****.key > ...

  3. 我的系统资源呢?php-fpm你知道吗?

    1:别的先不管咱们top一下.看看咱们的cpu ram swap的使用情况 由上图分析,可以看出共有602个进程,其中有601个进程休眠了.这好像有点不对劲,内核进程也就80个左右,加上memcach ...

  4. hash值

    任何类都继承public int hashCode()方法,该方法返回的值是通过将该对象的内部地址转换为一个整数来实现的,hash表的主要作用就是在对对象进行散列的时候作为key输入.我们需要每个对象 ...

  5. [LeetCode] Search in Rotated Array

    Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...

  6. 图解用HTML5的popstate如何玩转浏览器历史记录

    一.popstate用来做什么的?简而言之就是HTML5新增的用来控制浏览器历史记录的api. 二.过去如何操纵浏览器历史记录? window.history对象,该对象上包含有length和stat ...

  7. 动态Lambda表达式打印HelloWorld

    最近在用C#与数据库打交道.开发过程中采用了ORM模型(以前是纯sql玩法,复杂的逻辑用存储过程做). 为了能通过配置文件动态地查询字段,也就是说需要能这样写: db.AsQuery<T> ...

  8. Codeforces 618D Hamiltonian Spanning Tree(树的最小路径覆盖)

    题意:给出一张完全图,所有的边的边权都是 y,现在给出图的一个生成树,将生成树上的边的边权改为 x,求一条距离最短的哈密顿路径. 先考虑x>=y的情况,那么应该尽量不走生成树上的边,如果生成树上 ...

  9. java中初始化块、静态初始化块和构造方法

    (所谓的初始化方法init()是另一回事, 在构造方法之后执行, 注意不要混淆) 在Java中,有两种初始化块:静态初始化块和非静态初始化块.它们都是定义在类中,用大括号{}括起来,静态代码块在大括号 ...

  10. Android 通过浏览器打开应用

    在很多应用的web站,其实都有这样一个功能,就是直接在网页中打开应用,接下来的就来探讨一下这个功能的实现,有些地方也我还没弄明白,还请懂的大神指点. 首先,得说一点不好消息,在微信中,这样的方式是行不 ...