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?
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) .
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.
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 1HintIn 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, 子集合的和为i,i的值从0~m。值为i的子集合个数位bi。给出n,m,bi,求这n个数。
思路:
从0到m考虑,如果这个时候考虑到bi,那么如果bi大于0,那就存在i这个数。求出i的数量后,在b集合中减去i组合出来的所有数。具体看代码。
//
// main.cpp
// 1008
//
// Created by zc on 2017/8/8.
// Copyright © 2017年 zc. All rights reserved.
//
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
const int N=11000;
ll b[N],c[N],d[N];
int a[N];
int main(int argc, const char * argv[]) {
int T,n,m;
scanf("%d",&T);
while(T--)
{
memset(a,0,sizeof(a));
memset(c,0,sizeof(c));
scanf("%d%d",&n,&m);
for(int i=0;i<=m;i++) scanf("%lld",&b[i]);
int cnt=0;
a[0]=(int)log2((double)b[0]);
cnt+=a[0];
c[0]=b[0];
int mmax=0;
for(int i=1;i<=m&&cnt<n;i++)
{
if(b[i]==0) continue;
a[i]=(int)b[i]/b[0];
cnt+=a[i];
ll fz=1,fm=1;
for(int j=1;j<=a[i];j++)
{
ll t=j*i;
fz*=(a[i]-j+1);
fm*=j;
for(int k=mmax;k>=0;k--)
{
ll tmp=fz/fm*c[k];
d[k+t]+=tmp;
b[k+t]-=tmp;
}
}
mmax+=a[i]*i;
for(int i=0;i<=mmax;i++) c[i]+=d[i],d[i]=0;
}
cnt=0;
for(int i=0;i<=m&&cnt<n;i++)
{
for(int j=0;j<a[i];j++)
{
cnt++;
printf("%d",i);
if(cnt==n) printf("\n");
else printf(" ");
}
}
}
}