Rikka with Subset

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

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]

 
Source
思路:从小到大枚举加入的i值,如果当前的数字组合得到的i的数量小于b[i]那么就要加入对应个i值,同时更新f[i](数字和为i的集合个数)的值,直到填满n个数字。
代码:
  1. #include<bits/stdc++.h>
  2. #define db double
  3. #define ll long long
  4. #define ci(x) scanf("%d",&x)
  5. #define cd(x) scanf("%lf",&x)
  6. #define cl(x) scanf("%lld",&x)
  7. #define pi(x) printf("%d\n",x)
  8. #define pd(x) printf("%f\n",x)
  9. #define pl(x) printf("%lld\n",x)
  10. #define fr(i,a,b) for(int i=a;i<=b;i++)
  11. using namespace std;
  12. const int N=1e5+;
  13. const int mod=1e9+;
  14. const int MOD=mod-;
  15. const db eps=1e-;
  16. const int inf = 0x3f3f3f3f;
  17. int b[N],f[N],a[N];
  18. int main()
  19. {
  20. // ios::sync_with_stdio(false);
  21. // cin.tie(0);
  22. int t;
  23. ci(t);
  24. for(int ii=;ii<=t;ii++)
  25. {
  26. int n,m,c=;
  27. ci(n),ci(m);
  28. for(int i=;i<=m;i++) ci(b[i]);
  29. memset(f,,sizeof(f));
  30. f[]=;
  31. for(int i=;i<=m;i++){//我们要加入的数字i
  32. int v=b[i]-f[i];//加入v个i
  33. for(int j=;j<v;j++){
  34. a[++c]=i;
  35. for(int k=m;k>=i;k--){
  36. f[k]+=f[k-i];//更新当前组合的种数
  37. }
  38. }
  39. }
  40. for(int i=;i<=n;i++){
  41. printf("%d%c",a[i],i==n?'\n':' ');
  42. }
  43. }
  44. }

HDU 6092`Rikka with Subset 01背包变形的更多相关文章

  1. hdu 6092 Rikka with Subset 01背包 思维

    dp[i][j]表示前i个元素,子集和为j的个数.d[i][j] = d[i][j] + d[i-1][j-k] (第i个元素的值为k).这里可以优化成一维数组 比如序列为 1 2 3,每一步的dp值 ...

  2. HDU 2639 Bone Collector II(01背包变形【第K大最优解】)

    Bone Collector II Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  3. hdu 6092 Rikka with Subset(逆向01背包+思维)

    Rikka with Subset Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  4. HDU 6092 Rikka with Subset

    Rikka with Subset Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  5. hdu–2369 Bone Collector II(01背包变形题)

    题意:求解01背包价值的第K优解. 分析: 基本思想是将每个状态都表示成有序队列,将状态转移方程中的max/min转化成有序队列的合并. 首先看01背包求最优解的状态转移方程:\[dp\left[ j ...

  6. hdu 6092 Rikka with Subset (集合计数,01背包)

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

  7. hdu 6092 Rikka with Subset(多重背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6092 #include <cstdio> #include <iostream> ...

  8. HDU 6092 Rikka with Subset(dp)

    http://acm.hdu.edu.cn/showproblem.php?pid=6092 题意: 给出两个数组A和B,A数组一共可以有(1<<n)种不同的集合组合,B中则记录了每个数出 ...

  9. 2017 ACM暑期多校联合训练 - Team 5 1008 HDU 6092 Rikka with Subset (找规律)

    题目链接 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, s ...

随机推荐

  1. web本地存储

    Web本地存储 通过本地存储(Local Storage),web 应用程序能够在用户浏览器中对数据进行本地的存储. 在 HTML5 之前,应用程序数据只能存储在 cookie 中,包括每个服务器请求 ...

  2. 安装node/npm/webpack步骤

    nodejs软件的下载地址:https://nodejs.org/en/ 1.只要安装好了nodejs,就自动安装好了npm包. 2.在cmd中通过命令node -version查看是否安装好node ...

  3. Thinkjs学习1—概述及MVC的粗略理解

    1.概述 ThinkJS 是一款使用 ES6/7 特性全新开发的 Node.js MVC 框架,对于之前是纯前端的童鞋,可能不了解MVC框架是什么,不知道后台和前台怎么配合. 本教程以Thinkjs2 ...

  4. Visual Studio 2013怎么关闭智能提示?

    visual studio的智能提示加快了程序员写代码的速度,但是却让程序员更加的依赖编辑器,离开了智能提示,会忘记很多代码~,甚至会问自己,我还是程序员吗? 下面给出关闭visual studio智 ...

  5. [2014-11-11]使用Owin中间件搭建OAuth2.0认证授权服务器

    前言 这里主要总结下本人最近半个月关于搭建OAuth2.0服务器工作的经验.至于为何需要OAuth2.0.为何是Owin.什么是Owin等问题,不再赘述.我假定读者是使用Asp.Net,并需要搭建OA ...

  6. 大数据平台搭建-hadoop/hbase集群的搭建

    版本要求 java 版本:1.8.*(1.8.0_60) 下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downl ...

  7. 关于vue的一些总结

    最近学习了一段时间的vue js   除了路由没用过之外  基本上其他的都用过了 对于vue的一些用法  在此做一个总结.  开始使用vue之前 需要导入vuejs这个文件到项目中 <scrip ...

  8. 详解session

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcytp30 一.术语session 在我的经验里,session这个词被滥用的程度 ...

  9. poj3463 最短路和比最短路长1的路径数

    这题需要很好的理解Dij. 在Dij的基础上,每个点多一个次短路的长度和数量进行控制. 那么在队列中,最短路控制时出现n次,次短路控制出现n次.注意松弛条件中val值和最短路.次短路的关系. 这题需要 ...

  10. wait与sellp方法区别

    Java Thread(线程)案例详解sleep和wait的区别    上次对Java Thread有了总体的概述与总结,当然大多都是理论上的,这次我将详解Thread中两个常用且容易疑惑的方法.并通 ...