Rikka with Subset

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 1440    Accepted Submission(s): 721


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

 

Source
 

Recommend
liuyiding   |   We have carefully selected several similar problems for you:  6095 6094 6093 6092 6091 
 

Statistic | Submit | Discuss | Note

思路:动态规划+思维

因为已知了集合B要求集合A的序列,显然空集与全集的数量都为1,所以B0和Bm都为1

集合A中1的数量就等于B1,那么B2便可以由B1推出(排列组合的思想),B3可有B2推出,以此类推,采用01背包为题解决

#include <iostream>
#include<algorithm>
#include<string.h>
#include<stdint.h>
using namespace std;
const int maxn=10005; int a[maxn],b[maxn],c[maxn],dp[maxn];
//dp[i]表示:加和为i的子集个数 int main()
{
int t;
scanf("%d",&t);
int n,m;
while(t--)
{
scanf("%d%d",&n,&m);
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
memset(dp,0,sizeof(dp)); dp[0]=1;
for(int i=0;i<=m;i++)
{
scanf("%d",&b[i]);
}
int p=0,sum=0;
for(int i=1;i<=m;i++)
{
c[i]=b[i]-dp[i];//A序列中值为i的个数
for(int j=0;j<c[i];j++)
{
a[p++]=i;//对A序列赋值
for(int k=m;k>=i;k--)
{//处理成01背包问题
dp[k]+=dp[k-i];//和为k的子集个数相加去更新B序列 }
} }
for(int i=0;i<p-1;i++)
{
printf("%d ",a[i]); }
printf("%d\n",a[p-1]);
}
return 0;
}

2017杭电多校第五场Rikka with Subset的更多相关文章

  1. 2017杭电多校第五场11Rikka with Competition

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

  2. 2017杭电多校第六场1008 Kirinriki

    传送门 Kirinriki Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  3. 2018杭电多校第五场1002(暴力DFS【数位】,剪枝)

    //never use translation#include<bits/stdc++.h>using namespace std;int k;char a[20];//储存每个数的数值i ...

  4. 2017杭电多校第六场1011Classes

    传送门 Classes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Tota ...

  5. 2017杭电多校第六场03Inversion

    传送门 Inversion Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  6. 2017杭电多校第七场1011Kolakoski

    Kolakoski Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others) Tota ...

  7. 2017杭电多校第七场1005Euler theorem

    Euler theorem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others) ...

  8. hdu6356 Glad You Came 杭电多校第五场 RMQ ST表(模板)

    Glad You Came Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) ...

  9. [2019杭电多校第五场][hdu6630]permutation 2

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6630 题意为求出1-n,n个数的全排列中有多少种方案满足第一位为x,第n位为y,且相邻数字绝对值之差不 ...

随机推荐

  1. Network(poj 3694)

    题意:一个无向图可以有重边,下面q个操作,每次在两个点间连接一条有向边,每次连接后整个无向图还剩下多少桥(注意是要考虑之前连了的边,每次回答是在上一次的基础之上) /* tarjan+LCA 先用ta ...

  2. spring security 5.0 密码未加密报错

    使用spring security5.0后,配置文件中直接写普通的密码如:123456,会报错: java.lang.IllegalArgumentException: There is no Pas ...

  3. 【Tomcat】tomcat logs 目录下各日志文件的含义

      tomcat每次启动时,自动在logs目录下生产以下日志文件,按照日期自动备份.可以帮助我们更好的找出错误.   一. 认识各种目录的作用及记录的信息 目录

  4. Remove Duplicates from Sorted Array(参考)

    Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...

  5. spring boot项目自定义数据源,mybatisplus分页、逻辑删除无效解决方法

    Spring Boot项目中数据源的配置可以通过两种方式实现: 1.application.yml或者application.properties配置 2.注入DataSource及SqlSessio ...

  6. UUID使用

    import java.util.UUID; public static String getUUID() { UUID uuid =UUID.randomUUID(); String str = u ...

  7. Android 原生开发、H5、React-Native使用利弊和场景技术分享

    http://m.blog.csdn.net/article/details?id=51778086 发表于2016/6/28 18:52:46  1176人阅读      最近工作中接触到React ...

  8. sata express接口

    华硕z97主板的sata express接口目前没什么用,但随着电脑接口的发展,可能会占据一席之地. 1.顾名思义,SATA-Express是SATA接口 + PCI-Express的混合体,其理论带 ...

  9. How to remote debug neutron

    First of all, I will assume that you know how to use pydevd to remote debug normal python program. I ...

  10. java入门之——对象转型

    对象的类型转换是我们在编程的时候常常会遇到的,java平台也是如此.比方一些基本类型的数据转型和复合数据的转换. 举例 java语言中主要分为向上转型和向下转型,怎样来了解和掌握这两者转型的关系呢?首 ...