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. Linux下汇编语言学习笔记43 ---

    这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...

  2. SOJ 2930_积木城堡

    [题意]若干个城堡,给定每个城堡的积木数及每块积木的棱长.从城堡中抽出积木使每块城堡高度相同,求最大高度 [分析]城堡的积木选择可以看成01背包问题,从最矮的城堡高度开始依次递减,求出使每个背包都能装 ...

  3. Spring中通过java的@Valid注解和@ControllerAdvice实现全局异常处理。

    通过java原生的@Valid注解和spring的@ControllerAdvice和@ExceptionHandler实现全局异常处理的方法: controller中加入@Valid注解: @Req ...

  4. [bzoj2463][中山市选2009]谁能赢呢?_博弈论

    博弈论 bzoj-2463 中山市选-2009 题目大意:题目链接. 注释:略. 想法: 如果$n$是偶数的话就可以被多米诺骨牌恰好覆盖,这样的话只需要先手先走向(1,1)对应的第二段,后者必定会将棋 ...

  5. Codeforces 803F(容斥原理)

    题意: 给n个正整数,求有多少个GCD为1的子序列.答案对1e9+7取模. 1<=n<=1e5,数字ai满足1<=ai<=1e5 分析: 设f(x)表示以x为公约数的子序列个数 ...

  6. intellij使用tomcat搭建servlet运行时环境

    http://suiyu.online/2017/08/01/intellij%E4%BD%BF%E7%94%A8tomcat%E6%90%AD%E5%BB%BAservlet%E8%BF%90%E8 ...

  7. laralvel 关系多对多

  8. IOS开发UI篇--一个支持图文混排的ActionSheet

    一.简单介绍 UIActionSheet是IOS提供给我们开发人员的底部弹出菜单控件.一般用于菜单选择.操作确认.删除确认等功能.IOS官方提供的下面方式对UIActionView进行实例化: - ( ...

  9. 【C语言】推断一个数是否为2的n次方

    //推断一个数是否为2的n次方 #include <stdio.h> int is_two_n(int num) { if ((num&(num - 1))) //去掉一个1,推断 ...

  10. MySQL具体解释(21)------------缓存參数优化

    数据库属于 IO 密集型的应用程序.其主要职责就是数据的管理及存储工作. 而我们知道,从内存中读取一个数据库的时间是微秒级别,而从一块普通硬盘上读取一个IO是在毫秒级别,二者相差3个数量级.所以,要优 ...