【多校训练】 hdu 6092 Rikka with Subset

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  i s 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, 子集合的和为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(" ");
            }
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值