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. mybatis 批量保存,并且唯一约束

    1.主键返回在insert配置中添加两个属性 useGeneratedKeys="true" keyProperty="id" 2.唯一约束冲突可以使用 ON ...

  2. 记django从1.11.7升级到2.0.1

    第一步:升级django之后记录下django等其他相关依赖包的版本号. 在terminal中输入 pip freeze, 获取所有包的版本号.为了在升级不成功后可以回到低版本. 第二步:卸载再重装d ...

  3. Linux利用sed批量修改文件名

    初始文件名 # ls -lh total 5.5G -rw-r--r-- 1 root root 193K Sep 28 09:38 20180908.txt drwxr-xr-x 2 root ro ...

  4. Uber是一部无所不在的数字出行物联网

    "Uber化"是整合服务产业与智能车联网的知识经济,是数字时代展现个人化生活态度无可逆转的趋势,是新兴数字族群运用数字工具集体分享出行资源的平台. 搭过Uber的消费者,对其服务质 ...

  5. nginx平滑升级、在线添加模块(tengine 动态加载模块)

    http://www.orzace.com/how-to-upgrade-nginx/ 下面是nginx替换成tengine再加上lua 模块,(tengine-2.0.1版本暂时无法动态加载lua模 ...

  6. 数学--数论-- HDU6298 Maximum Multiple 打表找规律

    Given an integer nn, Chiaki would like to find three positive integers xx, yy and zzsuch that: n=x+y ...

  7. POJ 1905 Expanding Rods(二分)

    Expanding Rods Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 20224 Accepted: 5412 Descr ...

  8. 【K8S】K8S 1.18.2安装dashboard(基于kubernetes-dashboard 2.0.0版本)

    [K8S]K8S 1.18.2安装dashboard(基于kubernetes-dashboard 2.0.0版本) 写在前面 K8S集群部署成功了,如何对集群进行可视化管理呢?别着急,接下来,我们一 ...

  9. maven基本配置

    1.maven 是一个项目构建工具,如果在公司做大的项目 ,需要把项目拆分成很多子项目,为了方便各子项目之间协同开发和调试,一般都会使用maven.使用maven和以前web项目最大的不同是jar包的 ...

  10. 写了shell脚本想一键启动三台虚拟机的Zookeeper,却不知道为啥总是启动不了

    首先,一键启动的shell脚本是这样的 #! /bin/bash case $1 in "start"){ for i in node01 node02 node03 do ssh ...