From 59760891fb69207cc454058bc06cfcd79f547139 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Mon, 10 Oct 2016 01:21:34 +0800 Subject: [PATCH] Create 3561_huayunhualuo.cpp From http://blog.csdn.net/huayunhualuo/article/details/51622867 --- SDUTOJ/3561_huayunhualuo.cpp | 80 ++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 SDUTOJ/3561_huayunhualuo.cpp diff --git a/SDUTOJ/3561_huayunhualuo.cpp b/SDUTOJ/3561_huayunhualuo.cpp new file mode 100644 index 0000000..13a3574 --- /dev/null +++ b/SDUTOJ/3561_huayunhualuo.cpp @@ -0,0 +1,80 @@ +#include + +using namespace std; + +typedef long long LL; + +LL a[100]; + +LL b[40]; + +int ans; + +void Init() +{ + a[0] = 0; + + a[1] = 1; a[2] = 2; + + for(int i = 3;i<=47;i++) + { + a[i] = a[i-1]+a[i-2]; + } +} + +bool dfs(LL u,int st,int num) +{ + if(u == 0) + { + ans = num; + + return true; + } + + if(st == 0) return false; + + for(int i = st;i>=1;i--) + { + if(u >= a[i]) + { + b[num] = a[i]; + + if(dfs(u-a[i],i-1,num+1)) + { + return true; + } + } + } + return false; +} + +int main() +{ + Init(); + + int T; + + LL n; + + scanf("%d",&T); + + while(T--) + { + scanf("%lld",&n); + + if(dfs(n,47,0)) + { + printf("%lld=",n); + + for(int i = ans - 1;i >=0;i--) + { + if(i!=ans-1) printf("+"); + + printf("%lld",b[i]); + } + printf("\n"); + } + else printf("-1\n"); + } + return 0; +}