题目描述
算法1
(贪心)
贪心
可以证明当$N$是奇数时 无解
当$N$是偶数时,一定有解
贪心 从最大的二的偶数次幂开始
参考文献
C++ 代码
hhh有效代码就在Main()里,IN()是快读。
#include<bits/stdc++.h>
using namespace std;
#define For(i,x,y) for(int i = x;i<y;i++)
#define x first
#define y second
#define pb push_back
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
inline int IN(){
register int s = 0,w = 1;
register char c = getchar();
while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
while(c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
return s*w;
}
void Main(){
int n=IN();
if(n%2==1){puts("-1");return;}
while(n){
int a = 2;while(a<=n/2)a*=2;
printf("%d ",a);n-=a;
}
}
int main(){
Main();
return 0;
}
## HHH