hdu6092(留以纪念)

来源:互联网 发布:lv羊绒围巾 知乎 编辑:程序博客网 时间:2024/06/05 00:28


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 A1AnA1−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 A1AnA1−An

It is too difficult for Rikka. Can you help her?   
Input
The first line contains a number t(1t70)t(1≤t≤70), the number of the testcases. 

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

The second line contains m+1m+1 numbers B0Bm(0Bi2n)B0−Bm(0≤Bi≤2n).
Output
For each testcase, print a single line with nn numbers A1AnA1−An

It is guaranteed that there exists at least one solution. And if there are different solutions, print the lexicographic minimum one.
Sample Input
22 31 1 1 13 31 3 3 1
Sample Output
1 21 1 1




留个纪念

#include <iostream>

#include <stdio.h>

#include <string.h>

#include <math.h>

#include <algorithm>

int mm[10005];

int la[10005],ans[55];

long long a[10005];

using namespace std;


int main()

{

    int t,n,m;

    cin>>t;

    while(t--)

    {

        scanf("%d %d",&n,&m);

        

        for(int i=0;i<=m;i++)

        {

            scanf("%lld",&a[i]);

        }

        memset(la,0,sizeof(la));

        la[0]=1;

        

        for(int i=1;i<=n;i++)

        {

            int k=1;

            while(a[k]==0)

                k++;

            ans[i]=k;

            for(int j=m;j>=0;j--)

            {

                if(j+k<=m)

                {

                    la[j+k]+=la[j];

                    a[j+k]-=la[j];

                }

            }

        }

        for(int i=1;i<n;i++)

            printf("%d ",ans[i]);

        printf("%d\n",ans[n]);

    }

    return 0;

}


原创粉丝点击