Rikka with Subset

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1442    Accepted Submission(s): 723

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]$

//题意:给出 n,m 代表有 n 个数,和为 m ,设为数列 a[i],将 a[i] 的所有子集,的和求出,记录种数,得到 b[i] ,现给出 b ,求 a

//还是太水了,这种题竟然没有一点思路,01背包的反向做法即可推出 a ,具体做法是先找到最小的不为0的 b[i] ,i 即为 a 中最小的,然后,b[j]-=b[j-i] , O(n*m)

 # include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <bitset>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
#define lowbit(x) ((x)&(-x))
#define pi acos(-1.0)
#define eps 1e-8
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define LL long long
inline int scan() {
int x=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-') f=-; ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-''; ch=getchar();}
return x*f;
}
inline void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
#define MX 100005
//Code begin...
int dp[MX]; int main()
{
int t = scan();
while (t--)
{
int n = scan(),m = scan();
dp[]=;
for (int i=;i<m+;i++)
dp[i] = scan(); vector<int> ans;
for (int i=;i<=n;i++)
{
int k;
for (int j=;j<=m;j++)
if (dp[j]!=)
{
k = j;
ans.push_back(k);
break;
}
for (int j=k;j<=m;j++)
dp[j] -= dp[j-k]; }
for (int i=;i<n;i++)
printf("%d%c",ans[i],i!=n-?' ':'\n');
}
return ;
}

Rikka with Subset的更多相关文章

  1. HDU 6092`Rikka with Subset 01背包变形

    Rikka with Subset Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  2. HDU 6092 Rikka with Subset

    Rikka with Subset Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  3. HDU 6092 17多校5 Rikka with Subset(dp+思维)

    Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...

  4. hdu 6092 Rikka with Subset(逆向01背包+思维)

    Rikka with Subset Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  5. 2017杭电多校第五场Rikka with Subset

    Rikka with Subset Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  6. Rikka with Subset HDU - 6092 (DP+组合数)

    As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some mat ...

  7. 2017 ACM暑期多校联合训练 - Team 5 1008 HDU 6092 Rikka with Subset (找规律)

    题目链接 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, s ...

  8. HDU - 5829:Rikka with Subset (NTT)

    As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some mat ...

  9. hdu 6092 Rikka with Subset (集合计数,01背包)

    Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...

随机推荐

  1. Vue 过滤器filters

    1.示例代码 采用vue单文件组件,使用moment插件格式化日期 <template> <div> <h1>{{date | dateFormat}}</h ...

  2. jquery autoComplete的使用代码一则

    $(function() { $("#vipCustomer").autocomplete({ source : function(request, response) { $.a ...

  3. PNP管理器简析--基于ReactOS0.33

    CSDN上转悠了一圈发现关于PNP管理的文章不多.那就由我献个丑,记录自己对PNP管理器的看法. pnp管理器被描写叙述为向内核和应用程序提供关于设备拔插的通知,凭感觉,pnp管理器应该是个线程函数等 ...

  4. 【MyBatis学习03】原始dao开发方法及其弊端

    上一篇博文总结了一下mybatis的入门,接下来就要开发dao方法了,这篇博文主要总结一下mybatis中原始dao开发的方法,最后并总结一下原始dao开发方法的弊端.mybatis中dao开发应该使 ...

  5. spring学习笔记(六)

    1.配置环绕通知 需要实现的接口为  MethodInterceptor   代码举例 package com.huawei.aop; import org.aopalliance.intercept ...

  6. 打开eclipse中文件所在文件夹

    在myeclipse中选中文件后能够打开文件所在文件夹,可是eclipse中没有直接打开文件路径的功能.须要我们自己加入. 选择:Run -> External Tools -> Exte ...

  7. python 在Windows中描述路径时出现的问题

    问题的根本:windows读取文件可以用\,但在字符串里面\被作为转义字符使用,   python在描述路径时有两种方式: 'd:\\a.txt',转义的方式 r'd:\a.txt',声明字符串不需要 ...

  8. hdu1584 A strange lift (电梯最短路径问题)

    A strange lift Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  9. protobuf 在win10系统如何编译jar包

    最近在搞java服务器项目,前段要求用protobuf进行数据传输,以前没搞过,查了很多资料,走了一些弯路! 先把一些需要下载的链接放上来: protobuf下载地址:https://github.c ...

  10. 170. Two Sum III - Data structure design【easy】

    170. Two Sum III - Data structure design[easy] Design and implement a TwoSum class. It should suppor ...