Rikka with Subset

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

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 i

s 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
 
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e4+;
typedef long long LL;
LL dp[N],B[N];
int a[N];
int main(){
int n,m,T;
for(scanf("%d",&T);T--;){
memset(dp,,sizeof(dp));
memset(a,,sizeof(a));
scanf("%d%d",&n,&m);
for(int i=;i<=m;++i) scanf("%I64d",&B[i]);
dp[]=;
for(int i=;i<=m;++i){
if(dp[i]==B[i]) continue;
a[i]=B[i]-dp[i];
for(int j=;j<=a[i];++j) for(int k=m;k>=i;--k) dp[k]+=dp[k-i];
}
int i;
for(i=;i<=m;++i) if(a[i]--) {printf("%d",i);break;}
for(;i<=m;++i) while(a[i]--) printf(" %d",i);
puts("");
}
}

hdu6092 01背包的更多相关文章

  1. UVALive 4870 Roller Coaster --01背包

    题意:过山车有n个区域,一个人有两个值F,D,在每个区域有两种选择: 1.睁眼: F += f[i], D += d[i] 2.闭眼: F = F ,     D -= K 问在D小于等于一定限度的时 ...

  2. POJ1112 Team Them Up![二分图染色 补图 01背包]

    Team Them Up! Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7608   Accepted: 2041   S ...

  3. Codeforces 2016 ACM Amman Collegiate Programming Contest A. Coins(动态规划/01背包变形)

    传送门 Description Hasan and Bahosain want to buy a new video game, they want to share the expenses. Ha ...

  4. 51nod1085(01背包)

    题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1085 题意: 中文题诶~ 思路: 01背包模板题. 用dp[ ...

  5. *HDU3339 最短路+01背包

    In Action Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  6. codeforces 742D Arpa's weak amphitheater and Mehrdad's valuable Hoses ——(01背包变形)

    题意:给你若干个集合,每个集合内的物品要么选任意一个,要么所有都选,求最后在背包能容纳的范围下最大的价值. 分析:对于每个并查集,从上到下滚动维护即可,其实就是一个01背包= =. 代码如下: #in ...

  7. POJ 3624 Charm Bracelet(01背包)

    Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 34532   Accepted: 15301 ...

  8. (01背包变形) Cow Exhibition (poj 2184)

    http://poj.org/problem?id=2184   Description "Fat and docile, big and dumb, they look so stupid ...

  9. hdu3339 In Action(Dijkstra+01背包)

    /* 题意:有 n 个站点(编号1...n),每一个站点都有一个能量值,为了不让这些能量值连接起来,要用 坦克占领这个站点!已知站点的 之间的距离,每个坦克从0点出发到某一个站点,1 unit dis ...

随机推荐

  1. MySQL数据库入门详细笔记

    ps: 中括号[]里的内容都是可以省略的,按需要添加 数据库操作 创建数据库 语法:create database [if not exists] 数据名 charset=gbk; create da ...

  2. Docker虚拟化管理:30分钟教你学会用Docker

    关于Docker的官方介绍网上太多了我就不贴了,就实际体验来说Docker可以极大的简化环境搭建及服务部署的操作流程,大大降低部署的时间成本,解放你的双手. 本文不会深入讲解Docker底层架构及运行 ...

  3. 深度解析国内首个云原生数据库POLARDB的“王者荣耀”

    随着移动互联网.电子商务的高速发展,被使用最多的企业级开源数据系统MySQL面临着巨大挑战--为迎接"双11"的高并发要提前做好分库分表;用户不断激增要将读写分离才能应对每天上亿次 ...

  4. 使用JXL.jar实现JAVA对EXCEL的读写操作

    简介: jxl.jar是通过java操作excel表格的工具类库 jxl操作excel包括对象Workbook(工作簿),Sheet(工作表) ,Cell(单元格). 一个excel就对应一个Work ...

  5. swupdate 之 readback handler

    背景 使用 swupdate 作为 OTA 方案 ,有项目要求在写入数据到分区之后需要再次读出校验. 初步实现:readout-verify attribute 初步分析有两种方式 方案一 在每一笔数 ...

  6. 线程池(Java中有哪些方法获取多线程)

    线程池(Java中有哪些方法获取多线程) 前言 获取多线程的方法,我们都知道有三种,还有一种是实现Callable接口 实现Runnable接口 实现Callable接口 实例化Thread类 使用线 ...

  7. C++中const的特性

    目录(作用): 1:修饰变量,说明该变量不可以被改变: 2:修饰指针,分为只想常量的指针和自身是常量的指针 3:修饰引用,指向常量的引用,用于修饰形参,即避免了拷贝,有避免了函数对值的修改: 4:修改 ...

  8. 《C程序设计语言》 练习2-1

    问题描述 编写一个程序以确定分别由signed及unsigned限定的char.short.int及long类型变量的取值范围.采用打印标准头文件中的相应值以及直接计算两种方式实现 Write a p ...

  9. TransactionHelper

    public class TransactionHelper { public static OracleTransaction ora_Transaction = null; public stat ...

  10. Linux内核驱动学习(七)应用层直接操作GPIO

    文章目录 简介 原理图 节点 设置为输出 设置为输入 映射关系 debugfs pwm demo 简介 前面通过libgpio的方式介绍了内核空间对GPIO进行操作的接口,其做了较好的封装,同时Lin ...