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. 27.rm命令

    rm命令可以删除指定的文件或目录.也可以将某个目录及其下属的所有文件及其子目录均删除掉.对于链接文件,只是删除整个链接文件,而原有文件保持不变. 选项:-f:强制删除. -r:递归处理,将指定目录下的 ...

  2. React Native中自定义导航条

    这是2017年年初开始的公司的项目,对于导航条的要求很高,Android和iOS上必须用一致的UI,按钮位置还有各种颜色都有要求,而且要适应各种奇葩要求. 尝试了一下当时React Native自带的 ...

  3. Django中的content_type表

    models.py from django.db import models from django.contrib.contenttypes.models import ContentType # ...

  4. Vue项目中jQuery的引入

    1.安装jQuery依赖 npm install jquery --save-dev 2.在webpack.base.conf.js头部加入如下代码 var webpack = require(&qu ...

  5. Vue项目中实现图片懒加载

    个人网站 https://iiter.cn 程序员导航站 开业啦,欢迎各位观众姥爷赏脸参观,如有意见或建议希望能够不吝赐教! ---对于图片过多的页面,为了加速页面加载速度,所以很多时候我们需要将页面 ...

  6. CodeForces-259B]Little Elephant and Magic Square

      Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains ...

  7. unittest 管理用例生成测试报告

    # 登录方法的封装 from appium import webdriver from time import sleep from python_selenium.Slide import swip ...

  8. KMP+Tire树(模板)

    \(\color{Red}{KMP板子}\) #include <bits/stdc++.h> using namespace std; const int maxn=1e6+9; int ...

  9. N - Marriage Match II 网络流

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3081 推荐博客:https://www.cnblogs.com/liuxin13/p/4728131. ...

  10. c#一些常用知识点

    UID自动生成随机数 UID.Text = Guid.NewGuid().ToString(); GridView中常用格式化公式 <asp:BoundField DataField=" ...