贪心+IDDFS
数列生成的原则一定是ai=ai-1+aj(j<i)
为什么呢?
假设ai的分解中没有ai-1那么ai-1这个数就是毫无用处的,删掉更优
有了这个突破口就可以搜索了
还有因为OJ数据弱,这份代码像999,997都是TLE的
要是在考场上,,,,,果断打表。。。。。
//#define _TEST _TEST #include <cstdio> #include <cstring> #include <cstdlib> #include <iostream> #include <cmath> #include <algorithm> using namespace std; /************************************************ Code By willinglive Blog:http://willinglive.cf ************************************************/ #define rep(i,l,r) for(int i=(l),___t=(r);i<=___t;i++) #define per(i,r,l) for(int i=(r),___t=(l);i>=___t;i--) #define MS(arr,x) memset(arr,x,sizeof(arr)) #define LL long long #define INE(i,u,e) for(int i=head[u];~i;i=e[i].next) inline const int read() {int r=0,k=1;char c=getchar();for(;c<'0'||c>'9';c=getchar())if(c=='-')k=-1; for(;c>='0'&&c<='9';c=getchar())r=r*10+c-'0';return k*r;} ///////////////////////////////////////////////// int a[10000]; int an; int limit; bool vis[1010]; ///////////////////////////////////////////////// void printans(int dep) { printf("%d\n",dep); rep(i,1,dep) printf("%d ",a[i]); exit(0); } void dfs(int dep) { if(dep>limit) return; per(i,dep-1,1) if(a[i]+a[dep-1]<=an) { a[dep]=a[i]+a[dep-1]; if(a[dep]==an) printans(dep); vis[a[dep]]=1; dfs(dep+1); vis[a[dep]]=0; } } ///////////////////////////////////////////////// void input() { cin>>an; } void solve() { a[1]=1; if(an==1){printf("1\n1\n");} limit=2; for(;1<<limit < an;) limit++; for(;;limit++) dfs(2); { MS(vis,0); dfs(2); } } ///////////////////////////////////////////////// int main() { #ifndef _TEST freopen("std.in","r",stdin); freopen("std.out","w",stdout); #endif input(),solve(); return 0; }