題目描述
輸入輸出格式 輸入格式:
輸入輸出樣例
輸入樣例#1:
3
輸出樣例#1:
2
1 2
分析:
先把所有錢袋都可以看成一個取或不取的情況。那麼這些錢袋取或不取就可以看作0或1(取或不取)。所以我們就把錢袋裏錢的數量定爲2^n個。
代碼
#include <iostream>
#include <cstdio>
int main()
{
int m, tot = 0, ans[30];
scanf("%d", &m);
for(; m >> 1; m >>= 1)
ans[++tot] = (m >> 1) + (m & 1);
printf("%d\n1", tot + 1);
while(tot)
printf(" %d", ans[tot--]);
return 0;
}