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. XEP-0198:流管理

    ------------恢复内容开始------------ 原文来自:https://xmpp.org/extensions/xep-0198.html,只翻译了技术方面的内容. 摘要:这个规范定义 ...

  2. javascript SDK开发之webpack中eslint的配置

    eslint的好处就不多说了.代码检查,代码报错, 智能提示,让开发人员更规范的撸代码等等. 1.安装依赖 npm install --save-dev eslint eslint-friendly- ...

  3. 工具 在 Nuget 发布自己的包

    MSDN : https://docs.microsoft.com/zh-cn/nuget/quickstart/create-and-publish-a-package-using-visual-s ...

  4. 深入实践Spring Boot1.4 运行与发布

    1.4 运行与发布 本章实例工程的完整代码可以使用IDEA直接从GitHub的https://github.com/chen-fromsz/spring-boot-hello.git中检出,如图1-1 ...

  5. Spring Developer Tools 源码分析:三、重启自动配置'

    接上文 Spring Developer Tools 源码分析:二.类路径监控,接下来看看前面提到的这些类是如何配置,如何启动的. spring-boot-devtools 使用了 Spring Bo ...

  6. Java pdf转高清图片

    为什么80%的码农都做不了架构师?>>>   package com.hyb.kai.web.controller; import java.awt.image.BufferedIm ...

  7. Java通过反射技术动态创建对象(有参、无参构造)

    实现类: package com.ljy; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTarge ...

  8. CC2530ADC应用

    ADC单通道外部电压采集 需要设置一个上机位命令控制字符. 系统时钟初始化——32MHZ晶振 串口0函数初始化——设置串口对应引脚,波特率,清楚中断标志 串口0接收中断响应函数——U0DBUF将控制命 ...

  9. Coursera课程笔记----计算导论与C语言基础----Week 2

    计算机的历史与未来(Week 2) 计算机历史 早期计算机:手工计算器➡️机械计算器➡️计算机原型 现代计算机:电子管计算机➡️晶体管计算机➡️集成电路计算机➡️超大规模集成电路 早期的手工计算辅助工 ...

  10. 【Spark】SparkStreaming的容错机制

    文章目录 检查点机制 驱动器程序容错 工作节点容错 接收器容错 处理保证 检查点机制 Metadata checkpointing -- 将定义流计算的信息存入容错的系统如HDFS. Data che ...