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 nn positive A1−AnA1−An and their sum is mm. Then for each subset SS of AA, Yuta calculates the sum of SS.

Now, Yuta has got 2n2n numbers between [0,m][0,m]. For each i∈[0,m]i∈[0,m], he counts the number of iis he got as BiBi.

Yuta shows Rikka the array BiBi and he wants Rikka to restore A1−AnA1−An.

It is too difficult for Rikka. Can you help her?

InputThe first line contains a number t(1≤t≤70)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)n,m(1≤n≤50,1≤m≤104).

The second line contains m+1m+1 numbers B0−Bm(0≤Bi≤2n)B0−Bm(0≤Bi≤2n).OutputFor each testcase, print a single line with nn numbers A1−AnA1−An.

It is guaranteed that there exists at least one solution. And if there are different solutions, print the lexicographic minimum one.Sample Input

  1. 2
  2. 2 3
  3. 1 1 1 1
  4. 3 3
  5. 1 3 3 1

Sample Output

  1. 1 2
  2. 1 1 1

Hint

  1. 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]$
  2.  
  3. 题意:一个含有n个数的数组,他们的sum和是m,并且这n个数的所有子集的sum和的个数用一个数组b来表示。
    其中b[i] 表示 子集中sum和为i的有b[i]个。现在给你NMb数组,让你推出数组a,并输出字典序最小的那一个。
  4.  
  5. 思路:可以知道满足条件的只有一个数集set,所以只需要排序输出就是字典序最小的那个了。
    那么如何求数组a呢?,首先我们应该知道,如果有n0,会产生2^nsum和为0的集合。
    那么数组a0的数量直接就是log2(b[0])了。
    sum和为1的只需要用所以的sum和为0的集合加上一个1即可,
    所以num[1] = b[1]/b[0];
    然后定义数组dp[i],表示不用数字i,仅用小于i中的数凑出来sum和为i的集合数量。
    那么(b[i]-dp[i])/b[0] 就是Num[i]
    dp[i]的过程中用到dp的思想,细节见代码。
  1. if (dp[j] == ) continue;
  2. if (num[i] == ) break;

这步的代码可以节省时间复杂度。

code:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <queue>
  7. #include <stack>
  8. #include <map>
  9. #include <set>
  10. #include <vector>
  11. #include <iomanip>
  12. #define ALL(x) (x).begin(), (x).end()
  13. #define rt return
  14. #define dll(x) scanf("%I64d",&x)
  15. #define xll(x) printf("%I64d\n",x)
  16. #define sz(a) int(a.size())
  17. #define all(a) a.begin(), a.end()
  18. #define rep(i,x,n) for(int i=x;i<n;i++)
  19. #define repd(i,x,n) for(int i=x;i<=n;i++)
  20. #define pii pair<int,int>
  21. #define pll pair<long long ,long long>
  22. #define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
  23. #define MS0(X) memset((X), 0, sizeof((X)))
  24. #define MSC0(X) memset((X), '\0', sizeof((X)))
  25. #define pb push_back
  26. #define mp make_pair
  27. #define fi first
  28. #define se second
  29. #define eps 1e-6
  30. #define gg(x) getInt(&x)
  31. #define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
  32. using namespace std;
  33. typedef long long ll;
  34. ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
  35. ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
  36. ll powmod(ll a, ll b, ll MOD) {ll ans = ; while (b) {if (b % )ans = ans * a % MOD; a = a * a % MOD; b /= ;} return ans;}
  37. inline void getInt(int* p);
  38. const int maxn = ;
  39. const int inf = 0x3f3f3f3f;
  40. /*** TEMPLATE CODE * * STARTS HERE ***/
  41. int t;
  42. int n, m;
  43. ll b[maxn];
  44. int dp[maxn];
  45. int num[maxn];
  46. int c(int n, int m)
  47. {
  48. int sum = ;
  49. for (int i = n - m + ; i <= n; i++) sum *= i;
  50. for (int i = ; i <= m; i++) sum /= i;
  51. return sum;
  52. }
  53. int main()
  54. {
  55. //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
  56. //freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
  57. // gbtb;
  58. // cin >> t;
  59. scanf("%d", &t);
  60. while (t--)
  61. {
  62. MS0(num);
  63. MS0(dp);
  64. scanf("%d%d", &n, &m);
  65. repd(i, , m)
  66. {
  67. scanf("%lld", &b[i]);
  68. // cin >> b[i];
  69. }
  70. num[] = log2(b[]);
  71. num[] = b[] / b[];
  72. dp[] = b[];
  73. repd(i, , m)
  74. {
  75. for (int j = m; j >= ; j--)
  76. {
  77. if (dp[j] == ) continue;
  78. if (num[i] == ) break;
  79. for (int k = ; k <= num[i]; k++)
  80. {
  81. if (j + k*i <= m)
  82. {
  83. dp[j + k*i] += dp[j] * c(num[i], k);
  84. }
  85. }
  86. }
  87. if (i + <= m)
  88. {
  89. num[i+]=(b[i+]-dp[i+])/b[];
  90. }
  91. }
  92. bool flag = ;
  93. for (int i = ; i <= m; i++)
  94. {
  95. for (int j = ; j <= num[i]; j++)
  96. {
  97. if (!flag) printf("%d", i), flag = ;
  98. else printf(" %d", i);
  99. }
  100. }
  101. puts("");
  102. }
  103.  
  104. return ;
  105. }
  106.  
  107. inline void getInt(int* p) {
  108. char ch;
  109. do {
  110. ch = getchar();
  111. } while (ch == ' ' || ch == '\n');
  112. if (ch == '-') {
  113. *p = -(getchar() - '');
  114. while ((ch = getchar()) >= '' && ch <= '') {
  115. *p = *p * - ch + '';
  116. }
  117. }
  118. else {
  119. *p = ch - '';
  120. while ((ch = getchar()) >= '' && ch <= '') {
  121. *p = *p * + ch - '';
  122. }
  123. }
  124. }
  1.  

Rikka with Subset HDU - 6092 (DP+组合数)的更多相关文章

  1. hdu 3944 DP? 组合数取模(Lucas定理+预处理+帕斯卡公式优化)

    DP? Problem Description Figure 1 shows the Yang Hui Triangle. We number the row from top to bottom 0 ...

  2. HDU 6092 17多校5 Rikka with Subset(dp+思维)

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

  3. HDU 6092 Rikka with Subset

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

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

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

  5. HDU 6092`Rikka with Subset 01背包变形

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

  6. 2017杭电多校第五场Rikka with Subset

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

  7. Rikka with Subset

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

  8. hdu 3016 dp+线段树

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

  9. HDU 5928 DP 凸包graham

    给出点集,和不大于L长的绳子,问能包裹住的最多点数. 考虑每个点都作为左下角的起点跑一遍极角序求凸包,求的过程中用DP记录当前以j为当前末端为结束的的最小长度,其中一维作为背包的是凸包内侧点的数量.也 ...

随机推荐

  1. The operation could not be performed because OLE DB provider "SQLNCLI11" for linked server "SDSSDFCC...

    The operation could not be performed because OLE DB provider "SQLNCLI11" for linked server ...

  2. 爬取mzi.com妹子图片网站(requests库)

    看了崔大佬的文章,写了这个爬虫,学习了!原文地址 现在该网站加了反爬机制,不过在headers里加上refere参数就行了. 以下代码仅做学习记录之用: from bs4 import Beautif ...

  3. django加密解密api

    分别给出了两个API,一个创造密码,一个验证密码正好满足需求.于是赶紧试试: 首先,引入模块: 1 >>> from django.contrib.auth.hashers impo ...

  4. Cs231n课堂内容记录-Lecture 4-Part1 反向传播及神经网络

     反向传播 课程内容记录:https://zhuanlan.zhihu.com/p/21407711?refer=intelligentunit 雅克比矩阵(Jacobian matrix) 参见ht ...

  5. ASP.NET -- WebForm -- HttpResponse 类的方法和属性

    ASP.NET -- WebForm -- HttpResponse 类的方法和属性 1. HttpResponse 类的方法 (1) AddCacheDependency: 将一组缓存依赖项与响应关 ...

  6. June 5. 2018 Week 23rd Tuesday

    Learn to let go and be clear of where you really want to head for. 学会放手,同时也要弄清楚自己的真正所爱. From Kissing ...

  7. js中split()方法得到的数组长度

    js 中split(",")方法通过 ”,“ 分割字符串, 如果字符串中没有 “,” , 返回的是字符串本身 var str = “abc”://分隔符个数为0 var newSt ...

  8. Teradata 批量查找PI字段

    select * from dbc.indicesv where indextype in ('P','Q');

  9. 【SDOI2014】向量集

    [SDOI2014]向量集 题目描述 我们分析一波: 假设我们询问\((A,B)\),\(x_i>x_j\)若 \[ A\cdot x_i+B\cdot y_i>A\cdot x_j+B\ ...

  10. Python3新特性 类型注解 以及 点点点

    Python3新特性 类型注解 以及 点点点 ... Python3 的新特性 Python 是一种动态语言,变量以及函数的参数是 不区分类型 的 在 函数中使用类型注解 相当于 给 形参的 类型 设 ...