1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <stdio.h>
#include <vector>
#define L 20

using namespace std;

int n;
vector<int> v[L],r;
int vp[L];
int dp[1000100];

int main()
{
    scanf("%d",&n);

    for(int i=0;i<=n;i++)
    {
        v[__builtin_popcount(i)].push_back(i);
        dp[i]=1000000000;
    }
    for(int i=0;i<L;i++) v[i].push_back(1000000000);
    dp[0]=0;

    for(int i=0;i<n;i++)
    {
        for(int j=1;j<L;j++)
        {
            while(v[j][vp[j]]<=dp[i]) vp[j]++;
            dp[i+j]=min(dp[i+j],v[j][vp[j]]);
        }
    }

    int x=0;
    while(n)
    {
        x+=__builtin_popcount(dp[n]);
        r.push_back(dp[n]);
        n-=__builtin_popcount(dp[n]);
    }

    printf("%d\n",r.size());
    for(auto i: r) printf("%d ",i);

    return 0;
}