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

 
启发博客:http://www.cnblogs.com/stepping/p/7324970.html
官方题解:

1008 Rikka with Subset

签到题,大致的思想就是反过来的背包。

如果 B​i​​ 是 B 数组中除了 B​0​​ 以外第一个值不为 0 的位置,那么显然 i 就是 A 中的最小数。

现在需要求出删掉 i 后的 B 数组,过程大概是反向的背包,即从小到大让 Bj-=B​(j−i)​​。

时间复杂度 O(nm)。

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cmath>
#include<string>
#include<map>
#include<vector>
using namespace std; int b[];//最终结果b
int bb[];//目前得出的b
int a[]; int main()
{
int T,n,m,ans;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++)
scanf("%d",&b[i]);
memset(a,,sizeof(a));
memset(bb,,sizeof(bb));
bb[]=;
for(int i=;i<=m;i++)
{
a[i]=b[i]-bb[i];
for(int j=;j<=a[i];j++)//对bb进行更新
{
for(int k=m;k>=i;k--)//反着来避免已经加到结果里的数字再加一遍
bb[k]+=bb[k-i];
}
}
int flag=;
for(int i=;i<=m;i++)
for(int j=;j<=a[i];j++)
{
if(flag++) printf(" ");
printf("%d",i);
}
printf("\n");
}
return ;
}

HDU 6092 17多校5 Rikka with Subset(dp+思维)的更多相关文章

  1. HDU 6090 17多校5 Rikka with Graph(思维简单题)

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

  2. HDU 6095 17多校5 Rikka with Competition(思维简单题)

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

  3. HDU 6124 17多校7 Euler theorem(简单思维题)

    Problem Description HazelFan is given two positive integers a,b, and he wants to calculate amodb. Bu ...

  4. HDU 6049 17多校2 Sdjpx Is Happy(思维题difficult)

    Problem Description Sdjpx is a powful man,he controls a big country.There are n soldiers numbered 1~ ...

  5. HDU 6140 17多校8 Hybrid Crystals(思维题)

    题目传送: Hybrid Crystals Problem Description > Kyber crystals, also called the living crystal or sim ...

  6. HDU 6143 17多校8 Killer Names(组合数学)

    题目传送:Killer Names Problem Description > Galen Marek, codenamed Starkiller, was a male Human appre ...

  7. HDU 6045 17多校2 Is Derek lying?

    题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=6045 Time Limit: 3000/1000 MS (Java/Others)    Memory ...

  8. HDU 3130 17多校7 Kolakoski(思维简单)

    Problem Description This is Kolakosiki sequence: 1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1……. This seq ...

  9. HDU 6038 17多校1 Function(找循环节/环)

    Problem Description You are given a permutation a from 0 to n−1 and a permutation b from 0 to m−1. D ...

随机推荐

  1. 【Java】【4】关于Java中的自增自减

    摘要:理解j = j++与j = ++j的区别:正确用法:直接用j++,不要用前两种 正文: import java.util.*; public class Test{ public static ...

  2. Apache支持TRACE请求漏洞处理方案

    trace和get一样是http的一种请求方法,该方法的作用是回显收到的客户端请求,一般用于测试服务器运行状态是否正常. 该方法结合浏览器漏洞可能造成跨站脚本攻击.修复方法如下: 编缉/etc/htt ...

  3. 常用Linux源小记

    常用国内镜像站: 阿里云:http://mirrors.aliyun.com/ 中科大:http://mirrors.ustc.edu.cn/ 清华:https://mirrors.tuna.tsin ...

  4. Vuex的深入学习

    1.vuex 的dispatch和commit提交mutation的区别 (1)当你的操作行为中含有异步操作,比如向后台发送请求获取数据,就需要使用action的dispatch去完成了.其他使用co ...

  5. 微信小程序自动定位,通过百度地图根据经纬度获取该地点所在城市信息

    微信小程序获得经纬度 var that = this wx.getLocation({ type: 'wgs84', success(res) { console.log(res) that.setD ...

  6. 把旧系统迁移到.Net Core 2.0 日记 (13) --图形验证码

    参考这篇文章: http://www.cnblogs.com/yuangang/p/6000460.html using System; using System.IO; using System.D ...

  7. js地址多选实现,居住地,户口,职业,行业多选1

    开年来,公司就甩给我一个需求,其中一部分是对省市区地址多选,研究了一下午,发现一个已经写好的js可以使用, 遂研究改js的逻辑与代码,下面贴的是最初版本的js,仍有部分不符合需求,所以还有2.0版本的 ...

  8. how to get ubuntu current default runlevel

    [Purpose]        Learning how to get ubuntu current default  runlevel   [Eevironment]       Ubuntu 1 ...

  9. java.lang.UnsatisfiedLinkError:no dll in java.library.path

    报错:java.lang.UnsatisfiedLinkError:no dll in java.library.path 参考: Java调用Dll时,会出现no dll in java.libra ...

  10. 【转】Java迭代:Iterator和Iterable接口

    Java迭代 : Iterator和Iterable接口 从英文意思去理解 Iterable :故名思议,实现了这个接口的集合对象支持迭代,是可迭代的.able结尾的表示 能...样,可以做.... ...