zoukankan      html  css  js  c++  java
  • Rikka with Subset

    Rikka with Subset

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


    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 A1An 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 A1An.

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

     

    Input

    The first line contains a number t(1t70), the number of the testcases. 

    For each testcase, the first line contains two numbers n,m(1n50,1m104).

    The second line contains m+1 numbers B0Bm(0Bi2n).

     

    Output

    For each testcase, print a single line with n numbers A1An.

    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]$

     

    //题意:给出 n,m 代表有 n 个数,和为 m ,设为数列 a[i],将 a[i] 的所有子集,的和求出,记录种数,得到 b[i] ,现给出 b ,求 a

     

    //还是太水了,这种题竟然没有一点思路,01背包的反向做法即可推出 a ,具体做法是先找到最小的不为0的 b[i] ,i 即为 a 中最小的,然后,b[j]-=b[j-i] , O(n*m)

     1 # include <cstdio>
     2 # include <cstring>
     3 # include <cstdlib>
     4 # include <iostream>
     5 # include <vector>
     6 # include <queue>
     7 # include <stack>
     8 # include <map>
     9 # include <bitset>
    10 # include <set>
    11 # include <cmath>
    12 # include <algorithm>
    13 using namespace std;
    14 #define lowbit(x) ((x)&(-x))
    15 #define pi acos(-1.0)
    16 #define eps 1e-8
    17 #define MOD 1000000007
    18 #define INF 0x3f3f3f3f
    19 #define LL long long
    20 inline int scan() {
    21     int x=0,f=1; char ch=getchar();
    22     while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    23     while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    24     return x*f;
    25 }
    26 inline void Out(int a) {
    27     if(a<0) {putchar('-'); a=-a;}
    28     if(a>=10) Out(a/10);
    29     putchar(a%10+'0');
    30 }
    31 #define MX 100005
    32 //Code begin...
    33 int dp[MX];
    34 
    35 int main()
    36 {
    37     int t = scan();
    38     while (t--)
    39     {
    40         int n = scan(),m = scan();
    41         dp[0]=1;
    42         for (int i=0;i<m+1;i++)
    43             dp[i] = scan();
    44 
    45         vector<int> ans;
    46         for (int i=1;i<=n;i++)
    47         {
    48             int k;
    49             for (int j=1;j<=m;j++)
    50             if (dp[j]!=0)
    51             {
    52                 k = j;
    53                 ans.push_back(k);
    54                 break;
    55             }
    56             for (int j=k;j<=m;j++)
    57                 dp[j] -= dp[j-k];
    58 
    59         }
    60         for (int i=0;i<n;i++)
    61             printf("%d%c",ans[i],i!=n-1?' ':'
    ');
    62     }
    63     return 0;
    64 }
    View Code
  • 相关阅读:
    vue项目目录
    vue 组件传值,(太久不用就会忘记,留在博客里,方便自己查看)
    vuex学习心得
    vue2+webpack怎样分环境打包
    我的笔记啦
    如何在vue2.0项目中引用element-ui和echart.js
    Exsi SSH 服务配置
    CentOS 6 通过DVD快速建立本地YUM源
    为SSO 5.5恢复忘记的administrator@vsphere.local密码
    sshfs 通过ssh 挂载远程目录
  • 原文地址:https://www.cnblogs.com/haoabcd2010/p/7342001.html
Copyright © 2011-2022 走看看